如果直接添加到谓词,查询工作正常
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"author == %@", author];
[request setPredicate:predicate];
[self.managedObjectContext executeFetchRequest:request error:nil];
如果创建查询然后传递给谓词,则查询不起作用
有解决办法吗?我宁愿不将谓词本身传递给方法
Author 是 NSManagedObject 的子类
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "%@"'
[self fetchObjectsWithQuery:[NSString stringWithFormat:@"author == %@", author];
- (void)fetchObjectsWithQuery:(NSString *)query
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@", query];
[request setPredicate:predicate];
[self.managedObjectContext executeFetchRequest:request error:nil];
}