-1

在这里,我想过滤包含“cate = subcat”的数组中的字典,有人可以帮我吗

 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";
    }
)
4

3 回答 3

2
NSString *searchString = @"subcat"
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Cate = %@",searchString];
NSArray *array = [yourArray filteredArrayUsingPredicate:predicate];
if (array.count > 0)
{
// here goes your code
}
于 2013-04-06T06:56:00.440 回答
0

使用Linq to ObjectiveC,您可以按如下方式对其进行过滤:

NSArray* itemsInCategory = [menuArr where:^BOOL(id dic) {
    return [[dic objectForKey:@"Cate"] isEqualToString:@"subcat"];
}];

这会找到 Cate=subcat 的所有字典。

于 2013-04-06T06:55:49.613 回答
0

采用NSPredicate

NSArray *filtered = [yourArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(Cate LIKE[CD] %@)", @"subcat"]];
于 2013-04-06T06:58:08.893 回答