繁体   English   中英

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

[英]Throwing exception when searching for "(double quotes) using predicate

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

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""'

初学者的错误:您认为stringWithFormat和predicateWithFormat做相同的事情。 他们没有。 predicateWithFormat具有使谓词起作用的所有内在智慧。 stringWithFormat没有。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM