gpt4 book ai didi

xcode - iOS 7 中的 CoreData 迁移

转载 作者:行者123 更新时间:2023-12-01 23:56:20 27 4
gpt4 key购买 nike

终于让这个迁移工作了,这是一个很大的痛苦。

source code

在 iOS6 中一切正常,但在 iOS7 中应用程序崩溃

最佳答案

根据您在 http://openradar.io/15555487 上的评论和错误报告我猜完整的消息是这样的:

CoreData: error: failure reading metadata plist with data bytes: <33>
Unable to open database. Error: The file couldn’t be opened because it isn’t in the correct format.
Info: {
NSUnderlyingException = "An error <null> occurred converting the metadata plist data: <33>";
}

同样基于该报告以及您的源代码:您几乎肯定会在迁移后留下旧的 walshm 文件,这些文件在迁移后会导致问题移民。从 iOS 7 开始,Core Data 使用 WAL 模式日志记录。这意味着在复制或删除持久存储时,您需要担心几个额外的文件。如果您的存储文件名为 foo.sqlite,则在同一目录中还有一个 foo.sqlite-walfoo.sqlite-shm

您的代码删除了旧的 SQLite 文件并将其替换为新文件,但保留了现有的日志文件。这会导致数据不一致,因为日志文件不再对应于主 SQLite 文件。 SQLite 和 Core Data 无法理解剩下的内容,因此应用程序崩溃了。

解决方案最有可能确保清理多余的文件。当您调用此电话时:

success = [[NSFileManager defaultManager] removeItemAtURL:storeURL error:error];

...同时删除两个额外的文件。

为了将来的工作,将持久性存储文件放在它自己的目录中,没有其他文件是很有用的。然后,如果您需要删除存储,只需一步删除目录,无需关心 SQLite 或 Core Data 可能创建的其他额外文件。

关于xcode - iOS 7 中的 CoreData 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23460657/

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