美文网首页
CoreData自动迁移选项

CoreData自动迁移选项

作者: koreadragon | 来源:发表于2016-01-29 16:40 被阅读66次

//创建一个更新选项 字典类型
NSDictionary *option = @{NSInferMappingModelAutomaticallyOption:@"YES",NSMigratePersistentStoresAutomaticallyOption:@"YES"};

加到AppDelegate中以下方法

//创建一个更新选项 字典类型
NSDictionary *option = @{NSInferMappingModelAutomaticallyOption:@"YES",NSMigratePersistentStoresAutomaticallyOption:@"YES"};

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:option error:&error]) {
    // Report any error we got.
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
    dict[NSLocalizedFailureReasonErrorKey] = failureReason;
    dict[NSUnderlyingErrorKey] = error;
    error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
    // Replace this with code to handle the error appropriately.
    // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

相关文章

网友评论

      本文标题:CoreData自动迁移选项

      本文链接:https://www.haomeiwen.com/subject/qhvjkttx.html