我正在尝试创建一个谓词,但是得到一个错误。我得到错误'NSInvalidArgumentException',原因:'无法解析格式字符串“title包含[cd] @%”'我试过这样:
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
NSString *predicateString=[NSString stringWithFormat:@"title contains[cd] @% ",searchText];
request.predicate = [NSPredicate predicateWithFormat:predicateString];//error here
就像这样
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]];
request.predicate = [NSPredicate predicateWithFormat:@"title contains[cd] @%",searchText];//error here
答案 0 :(得分:3)
您的意思是%@
,而不是@%
,作为对象的格式说明符。