iOS Swift How to check Key Availability in NSMutableArray

陌路散爱 提交于 2020-01-17 06:43:52

问题


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";
    }
)

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


回答1:


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

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)
}


来源:https://stackoverflow.com/questions/43446612/ios-swift-how-to-check-key-availability-in-nsmutablearray

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!