2011-07-15 58 views
0

所以我想通過先設置謂詞然後查詢數據來從核心數據獲取自定義對象。下面是我在做什麼:NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dec LIKE[c] %@", [NSNumber numberWithInteger:[tempItemDec integerValue]]];NSPredicate,無法解析格式字符串

因此,十二月是NSNumber的和tempItemDec是NSString的,所以我必須先轉換成字符串NSInteger的然後包裹整數NSNumber的是能夠查詢,但得到錯誤說這個:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dec LIKE[c] %@"' 

我能夠從數據庫中查詢項目,如果我使用他們的名字爲例,但這我不明白?

任何想法?

回答

4

您還沒有關閉括號。另外,您需要爲LIKE運算符提供字符串參數,而不是數字。例如,使用[NSString stringWithFormat:@"%i", [tempItemDec integerValue]]

+0

我試過[NSPredicate predicateWithFormat:@「(dec LIKE [c]%@)」,但後來又出現了一個錯誤。 –

+0

什麼「其他錯誤」?看到我的編輯另一個可能的原因。 – omz

+0

現在用@「dec ==%@」工作,但它不適用於LIKE [E]不知道爲什麼。 –