0

我正在使用 github 上的一个项目,它可以让我使用NSFetchedResultsControllerand UICollectionView,该项目就是这个

但是当我以这种方式保存一个新对象时:

NSManagedObject *doc = [NSEntityDescription insertNewObjectForEntityForName:@"Document" inManagedObjectContext:self.managedObjectContext];
                    [doc setValue:[title contents] forKey:@"docName"];
[doc setValue:element valueforKey:@"Element"]

[self saveContext];

我收到此错误:

 CoreData: error: Serious application error.  Exception was caught during Core Data change  processing.  This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.  Can't perform collection evaluate with non-collection object. with userInfo (null)

我试图删除该项目,并且保存工作,所以我认为该项目中的问题,有什么帮助吗?

4

1 回答 1

0

我建议您导出 NSManagedObject 子类并按如下方式声明您的对象:

// At top of the file:
#import "Document.h"

// In your Method:
Document *doc = (Document *)[NSEntityDescription insertNewObjectForEntityForName:@"Document" inManagedObjectContext:self.managedObjectContext];
doc.docName = title.contents;

NSError *error = nil;
[self.managedObjectContext save:&error];

if (error != nil) {
    NSLog(@"Oh no! Something terrible happened! Error: %@", error);
}
else {
    NSLog(@"Saved! Yay!");
}
于 2013-01-25T01:45:02.167 回答