简体   繁体   中英

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

I am trying to search for the charecter " using predicate but it is throwing exception due to the format may I know the solution to overcome this:

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

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

The exception is:

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

Beginners mistake: You think that stringWithFormat and predicateWithFormat do the same thing. They don't. predicateWithFormat has all the cleverness built in to make predicates work. stringWithFormat doesn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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