首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS 7- CoreData迁移- Xcode 5

iOS 7- CoreData迁移- Xcode 5
EN

Stack Overflow用户
提问于 2013-11-13 17:16:33
回答 2查看 2.5K关注 0票数 4

我在执行CoreData迁移时遇到了一个非常奇怪的问题。

基本上,我有两个实体,在其中一个实体中我添加了一个属性,在另一个实体中,我将属性类型从NSString更改为NSArray(可转换的)。到目前为止,它运行良好,进行了测试,迁移后数据完整性完好无损。

如果我在Xcode 5上运行完全相同的代码(我不知道它是与iOS SDK7.0或Xcode 5有关),那么问题就会发生,但是迁移会运行并破坏数据。

最后,我创建了一个简单的项目来演示正在发生的事情。https://dl.dropboxusercontent.com/u/1393279/CoreDataMigration.zip

复制的步骤是:-在Xcode 5 (iOS SDK7.0)上,您可以使用模拟器-

1-打开项目"BeforeMigration“并执行。查看所创建的日志和数据,到目前为止没有问题;

2-停止项目;

3-打开项目"AfterMigration",构建并运行。

4-确保执行迁移,但数据已损坏:

2013-13 12:22:29.778 CoreDataMigration7223:70b CoreData: fetchRowForObjectID:* -NSKeyedUnarchiver initForReadingWithData::不可理解的存档(0x43,0x32,0x0,0x0,0x0,0x0,0x0,0x0)与userInfo (null) -11-13 12:22:29.782 CoreDataMigration7223:70b终止应用程序,原因:'NSInvalidArgumentException',原因:'** -NSKeyedUnarchiver initForReadingWithData:不可理解存档(0x43,0x32,0x0,0x0,0x0,0x0,0x0)‘

无法理解的存档意味着CoreData上的数据损坏。

很难理解的是,以前的代码是相同的,所以,如果这是一个逻辑问题,它应该发生在Xcode 4.5上。我寻找的CoreData差异,但没有找到任何相关。

如果有人知道问题出在哪里,我会很感激。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-26 16:44:57

在iOS 7中,核心数据SQLite存储的默认日志记录模式已改为写前日志记录(WAL),以提高可靠性、性能和并发性。

问题是我没有用核心数据移动-wal文件。修复它的一种方法是使用以下方法删除-wal:

代码语言:javascript
运行
复制
NSDictionary *options = @{NSSQLitePragmasOption:@{@"journal_mode":@"DELETE"}};

或者用以下方式移动-wal:

代码语言:javascript
运行
复制
- (NSPersistentStore *)migratePersistentStore:(NSPersistentStore *)store toURL:(NSURL *)URL options:(NSDictionary *)options withType:(NSString *)storeType error:(NSError **)error
票数 3
EN

Stack Overflow用户

发布于 2013-12-04 17:49:01

尝试使用moGenerator 链接并尝试以下步骤:

  • 使用MOGen (或MOGenerator)在每次构建时都从模型自动生成核心数据模型实体类(为此使用专用的预构建目标);
  • 在创建新数据模型时始终启用模型版本控制;
  • 在创建数据模型的新版本时:
代码语言:javascript
运行
复制
1. add new data model version - call it "new version"; set its Core Data Model Identifier to next desired version (like: 1.1 or 2.0, etc.). This is logical developer friendly identifier of  the model version - it does not force Core Data to treat this version differently unless critical changes are made to it;
2. rename what used to be current model version by appending its Version Identifier to the name. For example if it was "MyDataModel.xcdatamodel" that had its Version Identifier set to 1.1 - rename it into "MyDataModel\_1.1.xcdatamodel";
3. rename the newly added version into the simple model name, like "MyDataModel.xcdatamodel" and make it the Current Version. This way you always keep name of the current model version the same and your MOGen's activation/build scripts will not change (in case you do use MOGen - and you should);
4. modify the current model as needed;
5. depending on the scale of the changes made to the model, Core Data Lightweight Migration capabilities may handle it as is. If the changes are extansive you may need to define your own Mapping Model to help the Core Data to migrate an older data store into the latest version of the model;
6. clean your Product;
7. rebuild your Product;
8. test it.

Andrey Kornich的最佳做法

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19960181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档