2011-07-15 75 views
0

所以我想通过先设置谓词然后查询数据来从核心数据获取自定义对象。下面是我在做什么:NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dec LIKE[c] %@", [NSNumber numberWithInteger:[tempItemDec integerValue]]];NSPredicate,无法解析格式字符串

因此,十二月是NSNumber的和tempItemDec是NSString的,所以我必须先转换成字符串NSInteger的然后包裹整数NSNumber的是能够查询,但得到错误说这个:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dec LIKE[c] %@"' 

我能够从数据库中查询项目,如果我使用他们的名字为例,但这我不明白?

任何想法?

回答

4

您还没有关闭括号。另外,您需要为LIKE运算符提供字符串参数,而不是数字。例如,使用[NSString stringWithFormat:@"%i", [tempItemDec integerValue]]

+0

我试过[NSPredicate predicateWithFormat:@“(dec LIKE [c]%@)”,但后来又出现了一个错误。 –

+0

什么“其他错误”?看到我的编辑另一个可能的原因。 – omz

+0

现在用@“dec ==%@”工作,但它不适用于LIKE [E]不知道为什么。 –