您好,欢迎来到伴沃教育。
搜索
您的当前位置:首页CoreData自动迁移选项

CoreData自动迁移选项

来源:伴沃教育

//创建一个更新选项 字典类型
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();
}

Copyright © 2019- bangwoyixia.com 版权所有 湘ICP备2023022004号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务