2
0

Fixes to new store loading if not migrated.

This commit is contained in:
Maarten Billemont 2014-09-16 07:53:31 -04:00
parent 06c62f70ed
commit a043b7c049
2 changed files with 11 additions and 4 deletions

View File

@ -423,7 +423,7 @@
case MPElementTypeGeneratedShort: case MPElementTypeGeneratedShort:
case MPElementTypeGeneratedPIN: case MPElementTypeGeneratedPIN:
case MPElementTypeGeneratedName: { case MPElementTypeGeneratedName: {
NSAssert( NO, @"Cannot save content to element with generated type %lu.", (long)element.type ); wrn( @"Cannot save content to element with generated type %lu.", (long)element.type );
return NO; return NO;
} }

View File

@ -146,10 +146,17 @@ PearlAssociatedObjectProperty( NSManagedObjectContext*, MainManagedObjectContext
[self migrateStore]; [self migrateStore];
// Create a new store coordinator. // Create a new store coordinator.
self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: if (!self.persistentStoreCoordinator)
[NSManagedObjectModel mergedModelFromBundles:nil]]; self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:
[NSManagedObjectModel mergedModelFromBundles:nil]];
NSError *error = nil; NSError *error = nil;
[self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[self localStoreURL] NSURL *localStoreURL = [self localStoreURL];
if (![[NSFileManager defaultManager] createDirectoryAtURL:[localStoreURL URLByDeletingLastPathComponent]
withIntermediateDirectories:YES attributes:nil error:&error]) {
err( @"Couldn't create our application support directory: %@", [error fullDescription] );
return;
}
[self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:localStoreURL
options:@{ options:@{
NSMigratePersistentStoresAutomaticallyOption : @YES, NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES,