簡體   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