问题
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
ILTBis not key but its value for keyname.
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