首页 > 其他 > 详细

如何实现COCaData的版本迁移

时间:2014-09-05 16:24:12      阅读:417      评论:0      收藏:0      [点我收藏+]

第一步:选中你要迁移的cocaData文件,然后依次点击点击上方的editor、Add Model Version。然后创建新的cocaData文件,文件名可以自己改写。


第二步:改变当前的版本,操作为,点击新创建的cocaData文件,然后点击右边的Model Version,选择为当前的文件名


第三步:找到下面这个方法

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator

{

    if (_persistentStoreCoordinator != nil) {

        return _persistentStoreCoordinator;

    }

    

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

    

    NSError *error = nil;

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

第四步: 创建字典:


   NSDictionary *optionsDic = @{NSInferMappingModelAutomaticallyOption:@(YES), NSMigratePersistentStoresAutomaticallyOption:@(YES)};


第五步: 然后把options的参数改为创建的字典:

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:optionsDic error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

        abort();

    }    

    return _persistentStoreCoordinator;

}


本文出自 “周卫斌” 博客,请务必保留此出处http://wilbin.blog.51cto.com/9259255/1549298

如何实现COCaData的版本迁移

原文:http://wilbin.blog.51cto.com/9259255/1549298

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!