NSInvalidArgumentException',原因:'Unable to parse the format string "userName like %@ password like %@"'

NSInvalidArgumentException', reason: 'Unable to parse the format string "userName like %@ password like %@"'

标题

我正在尝试从 sql 文件中获取数据,但我一直收到 NSInvalidArgumentException。 如果有人能帮我弄清楚,我将不胜感激。

- (IBAction)signIn:(id)sender {
    //Creating a fetch request
    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
    //Create NSManagedObjectContext instance
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription  *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:context];
    NSFetchRequest *request = [[NSFetchRequest alloc]init];
    [request setEntity:entity];
    NSPredicate *predicate= [NSPredicate predicateWithFormat:@"userName like %@ password like %@",self.username_signin.text, self.password_signin.text];
    [request setPredicate:predicate];
    NSError *error;

}

格式错误,因为它有两部分,但你没有说明它们应该如何组合。它应该是这样的:

userName like %@ AND password like %@

此外,您很可能应该使用 = 而不是 like,因为您需要完全匹配而不是正则表达式类型匹配...

我不确定。

这一行

NSPredicate *predicate= [NSPredicate predicateWithFormat:@"userName like %@ password like %@",self.username_signin.text, self.password_signin.text];

改变

NSPredicate *predicate= [NSPredicate predicateWithFormat:@"userName like %@ && password like %@",self.username_signin.text, self.password_signin.text];