Objective c NSPredicate,无法分析格式字符串

Objective c NSPredicate,无法分析格式字符串,objective-c,cocoa-touch,cocoa,nspredicate,Objective C,Cocoa Touch,Cocoa,Nspredicate,因此,我试图通过先设置谓词,然后查询数据,从核心数据中获取自定义对象。下面是我正在做的:NSPredicate*谓词=[NSPredicate predicateWithFormat:@](dec LIKE[c]@,[NSNumber numberwhithinteger:[tempItemDec integerValue]]; 所以dec是NSNumber,tempItemDec是NSString,所以我必须首先将字符串转换为NSInteger,然后将整数包装为NSNumber才能进行查询,但

因此,我试图通过先设置谓词,然后查询数据,从核心数据中获取自定义对象。下面是我正在做的:
NSPredicate*谓词=[NSPredicate predicateWithFormat:@](dec LIKE[c]@,[NSNumber numberwhithinteger:[tempItemDec integerValue]];

所以dec是NSNumber,tempItemDec是NSString,所以我必须首先将字符串转换为NSInteger,然后将整数包装为NSNumber才能进行查询,但它会出现以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dec LIKE[c] %@"'
例如,如果我使用项目名称,我可以从数据库查询项目,但这我不明白


有什么想法吗?

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

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

我尝试了[NSPredicate predicateWithFormat:@”(dec LIKE[c]]@)但是我又遇到了另一个错误。现在可以使用@“dec==%@”,但是它不能使用像[c]这样的函数。我不知道为什么。因为你的参数是一个
NSNumber
,而不是
NSString
一样是一个字符串运算符。我尝试了[NSPredicate-predicateWithFormat:@”(像dec]@)但是我得到了另一个错误。现在使用@“dec==%@”可以使用它,但是它不能使用像[c]这样的函数。我不知道为什么。因为你的参数是一个
NSNumber
,而不是
NSString
LIKE
是一个字符串运算符。