I'm currently using Swiftdata to store data for an app I've deployed to the app store.
The problem is that the app does not build when I add a case of the Enum type to the model, so I decided to apply a MigrationPlan. I also decided that it is not a good idea to store the Enum type itself because of future side effects. The app is deployed in the app store with a model without a VersionedSchema, so the implementation is complete until we modify it to a model with a VersionedSchema.
This is Version1.
public enum TeamSchemaV1: VersionedSchema {
public static var versionIdentifier: Schema.Version = .init(1, 0, 0)
public static var models: [any PersistentModel.Type] {
[TeamSchemaV1.Team.self,
TeamSchemaV1.Lineup.self,
TeamSchemaV1.Player.self,
TeamSchemaV1.Human.self]
}
@Model
public final class Lineup {
...
public var uniform: Uniform
...
}
And you're having trouble migrating to Version2. The change is to rename the Uniform to DeprecatedUniform (the reason for the following change is to migrate even if it's just a property name)
public enum TeamSchemaV2: VersionedSchema {
public static var versionIdentifier: Schema.Version = .init(1, 0, 1)
public static var models: [any PersistentModel.Type] {
[TeamSchemaV2.Team.self,
TeamSchemaV2.Lineup.self,
TeamSchemaV2.Player.self,
TeamSchemaV2.Human.self]
}
@Model
public final class Lineup {
...
@Attribute(originalName: "uniform")
public var deprecatedUniform: Uniform
...
When you apply this plan and build the app, EXC_BAD_ACCESS occurs.
public enum TeamMigrationPlan: SchemaMigrationPlan {
public static var schemas: [VersionedSchema.Type] {
[TeamSchemaV1.self, TeamSchemaV2.self]
}
public static var stages: [MigrationStage] {
[migrateV1toV2]
}
public static let migrateV1toV2 = MigrationStage.lightweight(fromVersion: TeamSchemaV1.self,
toVersion: TeamSchemaV2.self)
}
I'm currently unable to migrate the data, which is preventing me from updating and promoting the app. If anyone knows of this issue, I would really appreciate your help.