iOS 17下Core Data轻量迁移部分用户失败问题求助
iOS 17下Core Data轻量迁移异常问题
问题详情
自iOS 17发布后,Core Data轻量迁移出现异常。当前NSPersistentStoreCoordinator使用的配置选项为:
[NSMigratePersistentStoresAutomaticallyOption: true as AnyObject, NSInferMappingModelAutomaticallyOption: true as AnyObject, NSSQLitePragmasOption: ["journal_mode": "DELETE"] as AnyObject]
添加持久化存储的代码如下:
try persistentCoordinator.addPersistentStore(ofType: NSInMemoryStoreType, configurationName: "InMemoryStore", at: nil, options: myOptions) try persistentCoordinator.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: "PersistentStore", at: myGroupURL, options: myOptions)
若添加存储失败,会删除数据库并重建。此前修改.xcdatamodel时未创建版本,iOS 17之前轻量迁移一直正常,但现在部分用户出现迁移失败。将.xcdatamodel从版本1更新到2后,部分用户收到错误:
An error occurred during persistent store migration., reason: Failed to open the store, underlyingReason: The model used to open the store is incompatible with the one used to create the store
此外,NSPersistentStoreCoordinator的MOM合并了另外两个模型,但这两个模型自问题出现后未做任何修改。问题出现在为实体添加属性或新增实体时,且排除这类操作直接导致的明确错误(若为此类原因,错误信息会有明确说明)。
咨询内容
- iOS 17是否有相关变更导致此问题?
- 以下方案是否可行,或有其他解决办法:
- 为
.xcdatamodel添加版本?尽管苹果文档未将其列为必需项 - 从
NSPersistentStoreCoordinator中移除另外两个模型? - 其他可行方案?
- 为
内容的提问来源于stack exchange,提问作者Gabriel Sória
相关产品推荐
相关产品推荐

