Post

Replies

Boosts

Views

Activity

I'm having trouble applying the SwiftData MigrationPlan.
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.
2
0
621
Dec ’23
How to change from non-versioned to versioned schema in swiftdata?
My app is using SwiftData, but I deployed it to the app store with no VersionedSchema applied without thinking about migrating the model. Now I need to migrate the data and I need help from someone who has experience moving from non-versioned to versioned. Assuming I currently have a version1, version2 schema, it works fine for the initial install situation, but when I migrate to version1, version2 in an app that is listed on the app store, I run into problems. I don't have any logs to show for it. Thread 1: EXC_BAD_ACCESS (code=2, address=0x16a6578f0) If anyone has had the same experience as above, please respond, thanks! Let me know what kind of logs you need and I'll add them as a comment.
1
1
658
Dec ’23