我有一系列字典,我想找到具有键“guid”所需值的字典。 无法使用此代码获取:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid = %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
答案 0 :(得分:5)
试试这个。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Name CONTAINS[cd] %@",searchBar.text];
filterdArray = [[hospitalArray filteredArrayUsingPredicate:predicate] mutableCopy];
其中Name
是数组下字典中包含的键。
答案 1 :(得分:1)
我想你忘了" ="登录。
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
答案 2 :(得分:0)
操作员条件已被遗忘;)
你需要添加一个双" ="像这样:
NSPredicate *filter = [NSPredicate predicateWithFormat:@"guid == %@", key];
NSArray *filteredContacts = [selectedValue filteredArrayUsingPredicate:filter];
我希望这可以帮到你!
答案 3 :(得分:0)
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(guid CONTAINS[c] %@)",key];
NSArray *array = [[NSArray arrayWithArray:sampleArray] filteredArrayUsingPredicate: predicate];
在上面的代码“fromDate”是字典的关键。
我希望这适合你。
答案 4 :(得分:0)
您可以尝试将NSPredicate发起为:
NSPredicate *filter = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"guid = '%@'", key]];
希望它有所帮助。
答案 5 :(得分:0)
试试这个,
NSArray *filtered = [array_with_dict filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(guid == %@)", @"desired value"]];