我在更改 NSManagedObject 的 BOOL 属性时发生崩溃。
保存对象的代码是:
self.detailItem.bookmark = [NSNumber numberWithBool:YES];
NSError *error = nil;
if (! [self.detailItem.managedObjectContext save:&error])
{
// Handle the error.
}
NSLog(@"%@", error);
错误:
Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet. with userInfo (null)
2011-08-18 15:41:32.866 Codes[5260:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.'
最佳答案
警告:这个答案是基于我根据错误信息做出的猜测;这可能是 100% 错误的!
该错误看起来像是一个格式不正确的 NSPredicate
。你可能有类似的东西
NSString *name = @"Bob";
[NSPredicate predictaeWithFormat:@"ANY %K IN %@", @"name", name];
看起来它可能会在 name = 'Bob'
中找到任何东西,但它不会,它会抛出异常 :(
如果您使用“IN”,则需要传递 NSSet 或 NSArray,即。
NSArray *names = [NSArray arrayWithObjects:@"Alice", @"Bob", nil];
[NSPredicate predictaeWithFormat:@"ANY %K IN %@", @"name", names];
这会找到名称为“Bob”或“Alice”的所有内容。
如果您只想搜索“Bob”,只需执行以下操作:
NSString *name = @"Bob";
[NSPredicate predictaeWithFormat:@"%K == %@", @"name", name];
关于iphone - 核心数据 NSInvalidArgumentException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7115034/