嗨,我有一个像这样的数组:
@[
@{@"Name":@"marko"; @"ids"=@[@"121",@"156",@"175",@"154"];},
@{@"Name":@"shine";@"ids"=@[@"175",@"165",@"154",@"187"];},
@{@"Name":@"David";@"ids"=@[@"857",@"297",@"156",@"254"];},
@{@"Name":@"Harry"; @ids"=@[@"297",@"154",@"867",@"201"];},
];
如何使用NSPredicate在@"156"
数组中获取字符串ids
的字典。
答案 0 :(得分:0)
试试这个:
NSDictionary *dict1 = @{@"Name": @"marko", @"ids" : @[@"121",@"156",@"175",@"154"]};
NSDictionary *dict2 = @{@"Name":@"shine", @"ids" : @[@"175",@"165",@"154",@"187"]};
NSDictionary *dict3 = @{@"Name":@"David", @"ids" : @[@"857",@"297",@"156",@"254"]};
NSDictionary *dict4 = @{@"Name":@"Harry", @"ids" : @[@"297",@"154",@"867",@"201"]};
NSArray *test = @[dict1, dict2, dict3, dict4];
NSArray *filtered = [test filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"ids CONTAINS[cd] %@", @"156"]];