- Core Data - Default Migration ( Manual )
- - (NSManagedObjectModel *)managedObjectModel
- {
- if (__managedObjectModel != nil)
- {
- return __managedObjectModel;
- }
- NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"App" withExtension:@"momd"];
- __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
- return __managedObjectModel;
- }
- /**
- Returns the persistent store coordinator for the application.
- If the coordinator doesn't already exist, it is created and the application's store added to it.
- */
- - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
- {
- if (__persistentStoreCoordinator != nil)
- {
- return __persistentStoreCoordinator;
- }
- NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"App.sqlite"];
- NSError *error = nil;
- __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
- NSLog(@"Which Current Version is our .xcdatamodeld file set to? %@", [[self managedObjectModel] versionIdentifiers]);
- NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
- //Commented for manual migration [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
- nil];
- if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
- {
- NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
- abort();
- }
- return __persistentStoreCoordinator
- }
- reason=Can't find mapping model for migration
- ## EDIT ##
- - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
- {
- if (__persistentStoreCoordinator != nil)
- {
- return __persistentStoreCoordinator;
- }
- NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"TestData.sqlite"];
- NSError *error = nil;
- __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
- NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
- nil];
- if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
- {
- NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
- abort();
- }
- return __persistentStoreCoordinator;
- }
- Report = "(<NSEntityDescription: 0x1708d0>) name Report, managedObjectClassName Report, renamingIdentifier Report, isAbstract 0, superentity name (null), properties {n action = "(<NSAttributeDescription: 0x170a30>), name action, isOptional 1, isTransient 0, entity Report, renamingIdentifier action, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0";n data = "(<NSAttributeDescription: 0x1709e0>), name data, isOptional 1, isTransient 0, entity Report, renamingIdentifier data, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)";n reportId = "(<NSAttributeDescription: 0x170a80>), name reportId, isOptional 1, isTransient 0, entity Report, renamingIdentifier reportId, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0";n timestamp = "(<NSAttributeDescription: 0x170ad0>), name timestamp, isOptional 1, isTransient 0, entity Report, renamingIdentifier timestamp, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)";n type = "(<NSAttributeDescription: 0x170990>), name type, isOptional 1, isTransient 0, entity Report, renamingIdentifier type, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0";n}, subentities {n}, userInfo {n}, versionHashModifier (null)";
- }, fetch request templates {
- }, reason=Can't find mapping model for migration}, {
- NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"cdm"];
- NSMappingModel *mappingModel = [[NSMappingModel alloc] initWithContentsOfURL:fileURL];
- NSArray *newEntityMappings = [NSArray arrayWithArray:mappingModel.entityMappings];
- for (NSEntityMapping *entityMapping in newEntityMappings) {
- [entityMapping setSourceEntityVersionHash:[sourceModel.entityVersionHashesByName valueForKey:entityMapping.sourceEntityName]];
- [entityMapping setDestinationEntityVersionHash:[destinationModel.entityVersionHashesByName valueForKey:entityMapping.destinationEntityName]];
- }
- mappingModel.entityMappings = newEntityMappings;
- BOOL ok = [migrationManager migrateStoreFromURL:sourceStoreURL
- type:sourceStoreType
- options:nil
- withMappingModel:mappingModel
- toDestinationURL:destinationStoreURL
- destinationType:destinationStoreType
- destinationOptions:nil
- error:&error];