【发布时间】:2017-03-06 07:08:52
【问题描述】:
有一个名为 "keyword" 的实体文件,其中包含逗号分隔值,例如 "8275,8276,8277"。现在使用 NSPredicate 搜索关键字匹配 this 并且传递值是 NSArray 的用户。尝试使用 (keywords contains[cd] %@) 获取单个值,不适用于数组。
谓词是这样的,
[NSPredicate predicateWithFormat:@"((eventId == %@) AND (keywords contains[cd] %@) AND (attendeeIsVisible == %@))",self.appDelegate.currentEvent.entityId,selectedTagID,[NSNumber numberWithInt:1]]
打印谓词后就像 -
eventId == 18230 AND keywords CONTAINS[cd] {"8275", "8276", "8277"} AND attendeeIsVisible == 1
尝试复合谓词也喜欢
NSMutableArray *parr = [NSMutableArray array];
for (id locaArrayObject in selectedTagID) {
[parr addObject:[NSPredicate predicateWithFormat:@"keywords contains[cd] %@ ",locaArrayObject]];
}
predicate = [NSPredicate predicateWithFormat:@"((eventId == %@) AND (keywords contains[cd] %@) AND (attendeeIsVisible == %@))",self.appDelegate.currentEvent.entityId,selectedTagID,[NSNumber numberWithInt:1]];
NSPredicate *predicateObj = [NSCompoundPredicate andPredicateWithSubpredicates:@[predicate, parr]];
也不行。知道我哪里做错了。
【问题讨论】:
-
已经检查过了,但无法获得它如何为“fetchRequest”工作的逻辑
-
@SantanuDasAdhikary 检查我的答案一次。
标签: ios objective-c arrays nspredicate nscompoundpredicate