使用谓词搜索"(双引号)时抛出异常

时间:2014-07-28 08:14:13

标签: ios objective-c iphone ios7

我正在尝试搜索字符“使用谓词,但由于格式可能会抛出异常,我可能知道克服此问题的解决方案:

NSString *predicateFormat = [NSString stringWithFormat:@"%@ like[c] \"'*%@*'\" AND %@ = \"%@\"", @"name", query, @"entitlementAccess", @"C"];

NSArray *groups =  [CoreDataManager managedObjectsForEntity:[DBGroup class]  withPredicate:[NSPredicate predicateWithFormat:predicateFormat] limit:limit];

例外是:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "name like[c] "'*a"*'" AND entitlementAccess = "C""'

1 个答案:

答案 0 :(得分:0)

初学者错误:你认为stringWithFormat和predicateWithFormat做同样的事情。他们没有。 predicateWithFormat具有内置的所有聪明功能,可以使谓词起作用。 stringWithFormat不是。

相关问题