2015-11-04 35 views
0

我正在嘗試編寫NSPredicate來提取用戶ID和claimID,我得到下面的錯誤。'無法解析格式字符串'claimID!=''&userID =%@「'

Terminating app due to uncaught exception NSInvalidArgumentException', reason: 'Unable to parse the format string "claimID != '' & userID = %@"'

我的代碼是 -

+(NSArray*)fetchNotificationsWithPredicate { 
    NSPredicate *predicate=[NSPredicate predicateWithFormat:@"claimID != '' & userID = %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"usernmae"]]; 
    NSLog(@"%@",[self fetchNotifications]); 
    NSArray *loginUsers = [DBUtils createAndExecuteFetchRequestWithPredicate:@"Notification" predicate:predicate]; 
    return loginUsers; 
} 

回答

0

望着predicate string format,它看起來像&不是一個有效的操作。你要麼AND&&。所以:。

@"claimID != '' && userID = %@" 

@"claimID != '' AND userID = %@" 

(這很可能不是唯一問題我從來沒有用過這個API,和我不是一個iOS開發者這是剛剛從文檔的檢查......)

+0

檢查...什麼革命性的新概念!這永遠不會流行。 – gnasher729

0

重寫你的斷言:

NSPredicate *predicate=[NSPredicate predicateWithFormat:@"claimID != '' AND userID MATCHES %@",[[NSUserDefaults standardUserDefaults] objectForKey:@"usernmae"]]; 

注:的號碼相匹配使用「=」和字符串匹配使用「MATCHES」的文件

+0

您好Jamil感謝您的回答,但現在我得到一個新的錯誤,即終止應用程序,由於未捕獲異常'NSInvalidArgumentException',原因:'無效謂詞:無RHS' –

+0

檢查其值爲零 – Jamil

+0

[[NSUserDefaults standardUserDefaults] objectForKey :@「usernmae」] – Jamil