SQLite到核心数据的迁移

SQLite到核心数据的迁移

本文介绍了SQLite到核心数据的迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在App Store上有一个实时应用程序,该应用程序使用 SQLite 作为数据库,现在有了下一个更新,我想在App中实现 Core Data ,从.sqlite加载所有数据文件而不破坏应用程序。我一直在阅读教程,但并没有太大帮助。我不知道该如何进行。

I have a live app on App Store which uses SQLite as database, now with the next update I want to implement Core Data in App loading all data from .sqlite file without breaking the App. I have been reading tutorials but it didn’t help much. I don't know how to proceed. Please, point me in right direction.

推荐答案

我认为@SaintThread是这里的主要问题。原因是Core Data并不是SQLite的包装,它是一个具有不同假设的API,只是内部使用了SQLite。如果您自己使用SQLite,Core Data不会尝试与您使用SQLite的方式兼容。

I think @SaintThread hit the main issue here. The reason for it is that Core Data is not a wrapper around SQLite-- it's a different API with different assumptions that just happens to use SQLite internally. Core Data doesn't attempt to be compatible with how you'd use SQLite if you were using SQLite on its own.

也就是说,如果您仍然想迁移,您必须设计一个Core Data模型,然后编写完全自定义的代码才能从现有的SQLite文件迁移到Core Data。您的代码需要从SQLite中读取所有内容,将其转换为新的Core Data表示形式,保存更改,然后删除现有的SQLite文件。

That said, if you still want to migrate, you'll have to design a Core Data model and then write fully custom code to migrate from your existing SQLite file to Core Data. Your code would need to read everything from SQLite, convert it to the new Core Data representation, save the changes, and then remove the existing SQLite files.

删除现有的SQLite文件,请确保还删除SQLite日志文件(如果有)。

When removing the existing SQLite file, make sure to also remove the SQLite journal files (if any).

这篇关于SQLite到核心数据的迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:50