Iphone 在数组中过滤听写
在这里,我想在包含“cate=subcat”的数组中过滤字典 有人能帮我吗Iphone 在数组中过滤听写,iphone,ios,objective-c,nsmutablearray,nsmutabledictionary,Iphone,Ios,Objective C,Nsmutablearray,Nsmutabledictionary,在这里,我想在包含“cate=subcat”的数组中过滤字典 有人能帮我吗 menuArr :( { Cate = subcat; Description = "Grilled Chicken"; Id = 2; Image = "http://asaraa.com/our_development/restaurant/admin/logo_image/large/28322grilled_chicken.jpg"
menuArr :(
{
Cate = subcat;
Description = "Grilled Chicken";
Id = 2;
Image = "http://asaraa.com/our_development/restaurant/admin/logo_image/large/28322grilled_chicken.jpg";
Name = "Grilled Chicken";
Price = 0;
Qty = "";
Title = "grilled chicken";
},
{
Cate = product;
Description = gravey;
Id = 12;
Image = "http://asaraa.com/our_development/restaurant/admin/logo_image/large/27166mutton.jpg";
Name = gravey;
Price = 50;
Qty = 1;
Title = gravey;
},
{
Cate = product;
Description = "Chicken Korma";
Id = 15;
Image = "http://asaraa.com/our_development/restaurant/admin/logo_image/large/77845Indian_chicken_recipes.jpg";
Name = "Chicken Korma";
Price = 99;
Qty = 1;
Title = "Chicken Korma";
},
{
Cate = subcat;
Description = "Chicken Sandwiches";
Id = 16;
Image = "http://asaraa.com/our_development/restaurant/admin/logo_image/large/67831chicken-sandwich-melt-0204_300.jpg";
Name = "Chicken Sandwiches";
Price = 0;
Qty = "";
Title = "Chicken Sandwiches";
}
)
使用,可以按如下方式对其进行过滤:
NSArray* itemsInCategory = [menuArr where:^BOOL(id dic) {
return [[dic objectForKey:@"Cate"] isEqualToString:@"subcat"];
}];
这将查找Cate=subcat的所有词典。使用
NSPredicate
NSString *searchString = @"subcat"
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Cate = %@",searchString];
NSArray *array = [yourArray filteredArrayUsingPredicate:predicate];
if (array.count > 0)
{
// here goes your code
}
NSArray *filtered = [yourArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(Cate LIKE[CD] %@)", @"subcat"]];
r u使用json响应?s先生,我使用json响应比较谓词过滤数组,