Образец облегченной миграции данных основных данных iOS? - PullRequest
0 голосов
/ 08 июля 2011

Apple предоставляет документ легковесной миграции, вот хороший образец до xcode4.

В xcode4 немного по-другому.

Спасибо за любые подсказки для простых примеров в xcode4, чтобы проиллюстрировать миграцию данных ядра.

1 Ответ

0 голосов
/ 05 января 2012

Просто обратите внимание, что добавление параметров NSDictionary и NSPersistentStoreCoordinator initializer теперь имеет аргумент параметров, установленный от nil до параметров

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"TradiesDB.sqlite"];

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

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
    {
        /*
            ...
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...