NSPredicate - Unable to parse the format string [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-03 22:27:26

Enclose the string in single quotes:

[NSPredicate predicateWithFormat:@"my_column = '193e00a75148b4006a451452c618ccec'"]

or better, use argument substitution:

[NSPredicate predicateWithFormat:@"my_column = %@", @"193e00a75148b4006a451452c618ccec"]

The second method avoids problems if the search string contains special characters such as ' or ".

Remark: Never use stringWithFormat when building predicates. stringWithFormat and predicateWithFormat handle the %K and %@ format differently, so combining these two methods is very error-prone (and unnecessary).

I think you have missed '' when checking for equality,

now try,

[NSPredicate predicateWithFormat:@"my_column='193e00a75148b4006a451452c618ccec'"];

Try

//Case Insensitive
fetchRequest.predicate=[NSPredicate predicateWithFormat:@"%K = [cd] %@",attributeName,itemValue];

//Case sensitive
fetchRequest.predicate=[NSPredicate predicateWithFormat:@"%K = %@",attributeName,itemValue];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!