[英]Searching dictionary in array using predicate
我有一系列字典,我想找到具有鍵“guid”所需值的字典。 無法使用此代碼獲取:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid = %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
試試這個。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Name CONTAINS[cd] %@",searchBar.text];
filterdArray = [[hospitalArray filteredArrayUsingPredicate:predicate] mutableCopy];
其中Name
是數組下字典中包含的鍵。
我想你忘記了“=”的標志。
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
操作員條件已被遺忘;)
你需要像這樣添加一個雙“=”:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
我希望這可以幫到你!
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(guid CONTAINS[c] %@)",key];
NSArray *array = [[NSArray arrayWithArray:sampleArray] filteredArrayUsingPredicate: predicate];
在上面的代碼“fromDate”是字典的關鍵。
我希望這適合你。
您可以嘗試啟動NSPredicate:
NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"guid = '%@'", key]];
希望能幫助到你。
試試這個,
NSArray *filtered = [array_with_dict filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(guid == %@)", @"desired value"]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.