开发者

NSPersistentDocument crash when creating persistent store

Recently I added a new entity into my Core Data model, so I cr开发者_C百科eated a new version for the model and a mapping model for it. However, now my NSPersistentDocument crashes with no obvious reason:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
                                                                        [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

BOOL success = [self configurePersistentStoreCoordinatorForURL:storeURL ofType:typeName modelConfiguration:nil storeOptions:options error:error]; // Line that crashes

The console logs:

*** -[NSCFArray insertObject:atIndex:]: attempt to insert nil

Here is the stack trace if it helps:

NSPersistentDocument crash when creating persistent store

Removing the mapping model doesn't help, so I guess its because the document tries to load the wrong/none data model but I haven't found a way to say that it should use a given data model.

Edit: When I use my own Core Data abstraction class for iOS, everything is fine. So the root of all evil seems to be NSPersistentDocument. Actually I don't want to switch back to NSDocument and have to implement the Core Data handling myself again, so any help is really appreciated!


You've probably made a change to the model that the automatic or "inferred" migration cannot handle. You will probably have to supply a mapping model to detail how the migration should be done.

Oh, and make sure that your old and new models are versioned i.e. has a version number. If not, the automatic migration can't tell which model is the old one and which the new.


Okay, I got it working by overwriting - (id)managedObjectModel and returning a valid managed object model myself. Looks like NSPersistentDocument isn't able to do this by itself for models with multiple versions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜