objective c - Filter and NSDictionary of NSArray of NSDictionary's -
i have nsdictionary contains 150 keys of boiler manufacturers. value each key nsarray of nsdictionary. each nsdictionary represents boiler properties:
nsdictionary boilerdata = { @"alpha" = [{name: boiler1, rating: 80}, {name:boiler2, rating: 90}], @"beta" = [{name: boiler3, rating: 80}, {name:boiler4, rating: 91}, {name:boiler5, rating: 78}], ... }
i able filter boiler's have rating of 80. know need nspredicate, can't figure out how build it? none of other articles i've found seem fit requirement.
nsdictionary *boilerdata = @{ @"alpha" : @[@{@"name": @"boiler1", @"rating": @80}, @{@"name": @"boiler2", @"rating": @90}], @"beta" : @[@{@"name": @"boiler3", @"rating": @98}, @{@"name": @"boiler4", @"rating": @80}, @{@"name": @"boiler5", @"rating": @90}] }; nsmutablearray *filteredarray = [[nsmutablearray alloc] init]; nspredicate *predicate = [nspredicate predicatewithformat:@"rating = 80"]; (nsarray *array in [boilerdata allvalues]) { [filteredarray addobjectsfromarray:[array filteredarrayusingpredicate:predicate]]; } nslog(@"all boilers rating = 80 : %@", filteredarray);
Comments
Post a Comment