启用CloudKit时SwiftData自定义迁移崩溃问题求助
问题:启用CloudKit时Core Data自定义迁移失败,存储版本无法更新
原上线应用仅有一个CDShift实体:
@Model final class CDShift { var identifier: UUID = UUID() var date: Date = Date() ... }
需对应用做以下更新:
- 添加新实体
DayPlan - 建立
DayPlan与CDShift的关联
已执行的迁移步骤:
- 用
SchemaV1封装原CDShift实体,版本号设为1.0.0 - 创建
SchemaV2,添加DayPlan实体及两者关联,版本号设为2.0.0 - 定义
MigrationPlan实现V1到V2的自定义迁移,在didMigrate方法中为所有原有CDShift创建对应的DayPlan
出现的问题:
- 创建
ModelContainer时触发崩溃,错误信息如下:
Unable to find a configuration named 'default' in the specified managed object model.
- 存储版本始终停留在1,无法更新至2
- 尝试轻量迁移无崩溃,但版本仍未更新
- 仅在启用CloudKit时出现此问题
内容的提问来源于stack exchange,提问作者Andrea Mario Lufino
相关产品推荐
相关产品推荐

