gpt4 book ai didi

ios - 核心数据迁移 : Possible to delete old store except for a few specific objects?

转载 作者:行者123 更新时间:2023-11-29 12:18:13 25 4
gpt4 key购买 nike

我们应用程序的新版本是完全重做的,几乎在所有方面都有所不同。阅读有关迁移的文章,我想我肯定会陷入沉重的阵营(增加关系),但我不确定我是否真的需要大部分数据,也不确定我是否有能力进行复杂的迁移。话虽这么说,我意识到用户可以保存最喜欢的故事,我想保留其中的一些数据(但作为故事实体的整个 NSMO 现在已经完全不同了)。但这就是我所需要的,只是来自几个 NSMO 的一些数据。

我已经使用 -isConfiguration:compatibleWithStoreMetadata: 进行了检测设置,并使用 -removeItemAtURL: 完全删除了旧商店作为麦芽汁情况,但是是否存在在我删除和构建新对象之前有什么方法可以获取一些东西吗?

最佳答案

是的,你可以用旧模型把旧存储站起来,然后从中取出数据,手动插入到新堆栈中。然后删除旧商店。实际的工作流程是:

  • 新模型是一个完全独立的文件
  • 新store是一个完全独立的文件(新文件名)

然后:

  1. 在磁盘上寻找旧文件名。如果它不存在就站起来
  2. 站起来旧堆栈。
  3. 站起来。
  4. 将数据从旧堆栈复制到新堆栈。
  5. 保存新堆栈。
  6. 释放旧堆栈并从磁盘中删除旧存储文件。

无需迁移。

i added old model file. then in the psc method, i detect if compatible and if not, stand up old stack, initiating model and psc both pointing to old one i just added and then creating context. added old class files for entity i need and fetched just the favorites and it worked! i know i can create new objects and insert to new stack, but what's the best way to save the new stack and release old when done? i still seem to be able to fetch even after removeitematurl. and is app delegate best place for all this?

首先,AppDelegate 不是这个地方。创建一个 DataController 子类 NSObject。将所有 Core Data 代码放在那里,然后传递 DataController

接下来,您不是在寻找迁移状态。您正在使用 NSFileManager 在磁盘上查找文件。如果旧文件存在,则将旧存储和新存储站起来,将数据复制过来。然后删除旧文件。

要释放旧堆栈,只需将引用(MOM、PSC 和 MOC)设置为nil。 ARC 将从内存中删除它们。

关于ios - 核心数据迁移 : Possible to delete old store except for a few specific objects?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31464090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com