因此,我尝试通过先设置谓词然后查询数据来从核心数据获取自定义对象。这就是我正在做的:NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dec LIKE[c] %@", [NSNumber numberWithInteger:[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]]
为例。
关于objective-c - NSPredicate,无法解析格式字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6710155/