2014-08-28 49 views
0

我創建了一個名爲Student的實體,用於存儲學生的詳細信息。構建用於NSArray的ID的NSPredicate

enter image description here

我試圖構建謂詞獲取基於有ID的幾個學生的詳細信息。

NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"Sid IN %@",@[@"1",@"2",@"3"]]]; 

始終得到錯誤

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "Sid IN (
    1, 
    2, 
    3 
)"' 
+0

是'Sid'是'NSNumber'的類型嗎? – Akhilrajtr 2014-08-28 04:59:14

+0

@Akhilrajtr它的NSString。 – Anand 2014-08-28 05:00:02

回答

2

你不應該(在幾乎所有情況下,沒有必要)混合stringWithFormat:predicateWithFormat:。在這種情況下,一個簡單的

[NSPredicate predicateWithFormat:@"Sid IN %@", @[@"1",@"2",@"3"]] 

應該做的。