'无法解析格式字符串" claimID!='' &安培; userID =%@"'

时间:2015-11-04 12:21:43

标签: ios objective-c iphone

我正在尝试编写NSPredicate来获取userID和claimID,我收到以下错误。

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;
}

2 个答案:

答案 0 :(得分:0)

查看predicate string format,看起来&不是有效的运算符。您要么AND要么&&。所以:

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

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

(这可能不是唯一的问题。我从未使用过这个API,而且我不是iOS开发人员。这只是检查文档......)< / p>

答案 1 :(得分:0)

重写你的谓词:

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

注意:用于数字匹配使用&#39; =&#39;并且对于字符串匹配,使用&#39; MATCHES &#39;