我在这里尝试了一些线程,但我无法找到解决问题的方法。 我想写一个像这样的NSPredicate:
NSPredicate* predicate = [NSPredicate predicateWithFormat: [NSString stringWithFormat:@"%@ IN %@", column, list]];
其中列变量的值为@“id”且列表包含四个数字。 id列是NSNumber列。
我收到以下错误,我不知道原因:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "id IN (
8,
5,
15,
22
)
问题不在于@“id”命名列(就像类型一样),我试图改变它并且它不起作用。 我应该如何正确使用IN运算符和核心数据?
答案 0 :(得分:2)
请勿混用stringWithFormat
和predicateWithFormat
。 (如上所述),
使用%K
作为关键路径:
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"%K IN %@", column, list];