NSPredicate,无法解析格式字符串
因此,我尝试通过先设置谓词然后查询数据来从核心数据获取自定义对象。这就是我正在做的事情: 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] %@"'
我能够从以下位置查询项目例如,如果我使用他们的名字,但是我不明白这个
有什么想法吗?
So I am trying to get a custom object from core data by setting predicate first then querying the data. Here is what I am doing: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dec LIKE[c] %@", [NSNumber numberWithInteger:[tempItemDec integerValue]]];
So the dec is NSNumber and tempItemDec is NSString so I must first convert the string to NSInteger then wrap the integer to NSNumber to be able to query, but it get error saying this:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dec LIKE[c] %@"'
I am able to query items from the DB if I use their name for example, but this I can't understand?
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你还没有关闭括号。此外,您需要为 LIKE 运算符提供字符串参数,而不是数字。例如,使用
[NSString stringWithFormat:@"%i", [tempItemDec integerValue]]
。You haven't closed the parenthesis. Also, you need to supply a string argument for the
LIKE
operator, not a number. Use[NSString stringWithFormat:@"%i", [tempItemDec integerValue]]
for example.