2011-09-19 25 views
1

當我創建查詢,包含撇號,我得到了錯誤:NSFetchRequest火災NSInvalidArgumentException查詢時ontains撇號

'NSInvalidArgumentException', reason: 'Unable to parse the format string "SELF.sale.ID == 0 AND ((SELF.dam contains[cd] 'Michael's') OR (SELF.name contains[cd] 'Michael's') OR (SELF.purchaserLocation contains[cd] 'Michael's') OR (SELF.purchaserName contains[cd] 'Michael's') OR (SELF.sire contains[cd] 'Michael's') OR (SELF.vendor contains[cd] 'Michael's'))"'

我已經試過有兩個apostrpohes但仍然得到了同樣的錯誤,以取代單引號。 當查詢不包含撇號時,一切都很順利。 感謝

+0

發佈您的代碼,你構建'NSPredicate'。 – Mundi

+0

有必要用撇號撇號替換撇號 –

回答

0

我的壞,我不得不更換轉義字符串\」

0

如果在使用[NSPredicate predicateWithFormat]時用單引號將格式佔位符包圍在格式字符串中,就可能發生這種情況。這些引號是不需要的。

錯誤的榜樣:

NSPredicate *myPred = [NSPredicate predicateWithFormat:@"name = '%@'"; 

正確的示例:

NSPredicate *myPred = [NSPredicate predicateWithFormat:@"name = %@";