[英]iOS Swift How to check Key Availability in NSMutableArray
我有一些像這樣的NSMutableArray:
(
{
name = "ILTB";
source = "iltb.net";
},
{
name = "Baran Bench";
source = "baranbench.com";
},
{
name = "Income Tax India 1";
source = "Income Tax India 1";
}
)
如何在此NSMutableArray中檢查密鑰可用性。 例如,我需要檢查“ ILTB”是否已經在我的MutableArray中。
首先,
ILTB
不是密鑰,而是密鑰name
值。
您可能想從數組中搜索。 現在在Swift中而不是NSArray
使用Swift的本機字典數組,然后以這種方式使用first(where:)
。
let array = [[String:String]]()
if let res = array.first(where: { $0["name"] == "ILTB" }) {
print(res)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.