iphone - 核心数据 NSInvalidArgumentException 错误

标签 iphone objective-c cocoa-touch core-data crash

我在更改 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/

相关文章:

iphone - 针对手持式样式表

ios - TableView (_ :editActionsForRowAt:) is not called on iOS 9. 3

iphone - iOS 上的 Segues 与 addSubView

iphone - 没有 Storyboard或 xib 文件的 iOS 通用应用程序

ios - 在一个窗口中嵌入多个 View Controller

ios - 单击时将 TableView 单元格编号传递到另一个 View ,一开始始终为 null

iphone - 如何复制 NSMutableAttributedString

iphone - 如何在 iPhone SDK 中列出所有文件夹及其子目录/文件?

iphone - iPhone 中的图像尺寸不正确

iphone - Xcode 4.0.2 启动时崩溃