【发布时间】:2021-08-15 20:20:07
【问题描述】:
我有一个 NSMutableArray (self.allPeople) 包含许多字典(人)。也就是说,我还有一个包含一系列数字的 NSMutableArray (self.participants):
self.participants
Here they are: (
179,
125,
231
)
我想要过滤 self.allPeople,并且只返回键“nid”等于 self.participants 中包含的数字之一的字典。
如何使用 self.participants 中的每个数字过滤 self.allPeople (valueForKey:@"nid")?
如果我只想按单个字符串值进行过滤,但我需要它来过滤所有数字,则此方法有效:
NSPredicate *p = [NSPredicate predicateWithFormat:@"nid CONTAINS[cd] %@", @"179"];
self.results = [self.allPeople filteredArrayUsingPredicate:p];
【问题讨论】:
标签: ios objective-c nspredicate