iOS Swift 如何检查 NSMutableArray 中的密钥可用性 [英] iOS Swift How to check Key Availability in NSMutableArray

查看:54
本文介绍了iOS Swift 如何检查 NSMutableArray 中的密钥可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 NSMutableArray 像:

I am having some set of NSMutableArray like:

(
        {
        name = "ILTB";
        source = "iltb.net";
    },
        {
        name = "Baran Bench";
        source = "baranbench.com";
    },
        {
        name = "Income Tax India 1";
        source = "Income Tax India 1";
    }
)

如何检查此 NSMutableArray 中的密钥可用性.例如,我需要检查ILTB"是否已经在我的 MutableArray 中.

How to check Key availability in this NSMutableArray. For Example I need to check "ILTB" is already in my MutableArray or not.

推荐答案

首先ILTB 不是键,而是键name 的值.

First of all ILTB is not key but its value for key name.

您可能想从数组中搜索.现在在 Swift 中而不是 NSArray 使用 Swift 的本机字典数组,然后使用 first(where:) 这种方式.

You probably want search from array. Now in Swift instead of NSArray use Swift's native array of dictionary and then use first(where:) this way.

let array = [[String:String]]()
if let res = array.first(where: { $0["name"] == "ILTB" }) {
    print(res)
}

这篇关于iOS Swift 如何检查 NSMutableArray 中的密钥可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆