edit
I have reposted this here: Core Data & UIManagedDocument in Xcode 4.3: Can't merge models
I managed to get a different error to show.
end of edit
so I am making a Core Data App that used a shared UIManagedDocument
. I access this UIManagedDocument
using a helper class DocumentHandler
. The hope is that I'll be able to use it like this in another class's viewWillAppear
:
if (!self.document) {
[[DocumentHandler sharedDocumentHandler] performWithDocument:^(UIManagedDocument *document) {
self.document = document;
[self setupFetchedResultsController];
}];
}
`
- (id)init {
self = [super init];
if (self) {
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"MyJimDocument"];
self.document = [[UIManagedDocument alloc] initWithFileURL:url];
// Set our document up for automatic migrations
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
self.document.persistentStoreOptions = options;
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(objectsDidChange:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.document.managedObjectContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contextDidSave:)
name:NSManagedObjectContextDidSaveNotification
object:self.document.managedObjectContext];
}
return self;
}
- (void)performWithDocument:(OnDocumentReady)onDocumentReady {
void (^OnDocumentDidLoad)(BOOL) = ^(BOOL success) {
onDocumentReady(self.document);
};
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]) {
[self.document saveToURL:self.document.fileURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:OnDocumentDidLoad];
} else if (self.document.documentState == UIDocumentStateClosed) {
[self.document openWithCompletionHandler:OnDocumentDidLoad];
} else if (self.document.documentState == UIDocumentStateNormal) {
OnDocumentDidLoad(YES);
}
}
'
Using the context from the document I create NSManagedObjects (standard Core Data stuff, right?). The problem is that I get this error when I run the app:
"Can't merge models with two different entities named"
I'm in over my head with this DocumentHandler, and I hope this is an easy fix I'm too stupid/inexperienced to see.
I havent' made separate versions of the data model or anything and I'm not trying to migrate anything. I just want to run this app for the first time!
Thanks for reading.