iOS核心数据IN运算符,无法解析格式字符串

时间:2014-02-03 19:27:47

标签: ios sql core-data

我在这里尝试了一些线程,但我无法找到解决问题的方法。 我想写一个像这样的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运算符和核心数据?

1 个答案:

答案 0 :(得分:2)

请勿混用stringWithFormatpredicateWithFormat。 (如上所述), 使用%K作为关键路径:

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"%K IN %@", column, list];