3
votes

I follow this nice tutorial http://mipostel.com/index.php/home/70-core-data-migration-standard-migration-part-2 to do my core data migration.

For some strange reason i always get NULL in the mappingModel in these lines:

 NSMappingModel *mappingModel = [NSMappingModel mappingModelFromBundles:nil
                                                                forSourceModel:sourceModel
                                                              destinationModel:destinationModel];

(line 191 in the linked code)

I tried to create a very simple derived version of the model, I recreated a mappingModel a 1000 times, made sure that the mapping model file is in the project directory - but this call always returns NULL.

Anybody has an idea what is wrong here?

ps I was just wondering that setting the migration options is called AFTER the mapping Model is used.

   NSURL *storeUrl = [NSURL fileURLWithPath:storePath];   
    NSError *error;   
    NSDictionary *pscOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                [NSNumber numberWithBool:NO], NSInferMappingModelAutomaticallyOption,
                                nil];

    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                                  configuration:nil
                                                            URL:storeUrl
                                                        options:pscOptions
                                                          error:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }   

(lines 123...)

Anyway

Why can't the mapping model be found ?

pss couldn't help holding back :-) this core data migration stuff is much too complicated and difficult compared to doing simple SQL DB migration - wasting soooo much time.

So a BIG THANKS in advance!

1
actually as it turned out the tutorial seems to be faulty - so try to find another one before wasting as much time as I did.... :-()user387184

1 Answers

4
votes

I followed that same tutorial and ended up having to manualy open my mapping model by URL

  NSString *mappingModelPath = [[NSBundle mainBundle] pathForResource:@"mappingModel10" ofType:@"cdm"];
    NSLog(@"mapping model path:%@", mappingModelPath);
    NSURL *mappingModelUrl = [NSURL fileURLWithPath:mappingModelPath];
    NSMappingModel *mappingModel = [[NSMappingModel alloc] initWithContentsOfURL:mappingModelUrl];

I found the file name for my mapping model by looking in my App's bundle.