Post

Replies

Boosts

Views

Activity

Reply to Error message when opening a SwiftData ModelContainer
I am facing the same error in my app. Here is an example of my code to reproduce it. ModelContainer: var sharedModelContainer: ModelContainer = { let modelConfiguration = ModelConfiguration(schema: Schema(versionedSchema: CurrentModelSchema.self), isStoredInMemoryOnly: false) do { let container = try ModelContainer( for: Schema(versionedSchema: CurrentModelSchema.self), migrationPlan: AppMigrationPlan.self, configurations: [modelConfiguration] ) return container } catch { fatalError("Could not create ModelContainer: \(error)") } }() CurrentModelSchema: /// Current model schema typealias CurrentModelSchema = ModelSchemaV3 /// Model references typealias Test1 = CurrentModelSchema.Test1 typealias Test1 = CurrentModelSchema.Test2 The typealiases Test1 and Test2 are @Model-Classes. AppMigrationPlan: enum AppMigrationPlan: SchemaMigrationPlan { static var schemas: [any VersionedSchema.Type] { [ModelSchemaV1.self, ModelSchemaV2.self, ModelSchemaV3.self] } static let migrateV1toV2 = MigrationStage.custom( fromVersion: ModelSchemaV1.self, toVersion: ModelSchemaV2.self, willMigrate: nil, // Logic to perform the migration of V1 schema didMigrate: { context in // Logic to perform the migration of V2 schema let tests = try context.fetch(FetchDescriptor<ModelSchemaV2.Test1>()) // Do the migration operation.... } try context.save() } ) static let migrateV2toV3 = MigrationStage.lightweight( fromVersion: ModelSchemaV2.self, toVersion: ModelSchemaV3.self ) static var stages: [MigrationStage] { // Migration stage that will be performed [migrateV1toV2, migrateV2toV3] } } Please let me know if you need more details to reproduce it.
Oct ’24
Reply to Error message when opening a SwiftData ModelContainer
I am facing the same error in my app. Here is an example of my code to reproduce it. ModelContainer: var sharedModelContainer: ModelContainer = { let modelConfiguration = ModelConfiguration(schema: Schema(versionedSchema: CurrentModelSchema.self), isStoredInMemoryOnly: false) do { let container = try ModelContainer( for: Schema(versionedSchema: CurrentModelSchema.self), migrationPlan: AppMigrationPlan.self, configurations: [modelConfiguration] ) return container } catch { fatalError("Could not create ModelContainer: \(error)") } }() CurrentModelSchema: /// Current model schema typealias CurrentModelSchema = ModelSchemaV3 /// Model references typealias Test1 = CurrentModelSchema.Test1 typealias Test1 = CurrentModelSchema.Test2 The typealiases Test1 and Test2 are @Model-Classes. AppMigrationPlan: enum AppMigrationPlan: SchemaMigrationPlan { static var schemas: [any VersionedSchema.Type] { [ModelSchemaV1.self, ModelSchemaV2.self, ModelSchemaV3.self] } static let migrateV1toV2 = MigrationStage.custom( fromVersion: ModelSchemaV1.self, toVersion: ModelSchemaV2.self, willMigrate: nil, // Logic to perform the migration of V1 schema didMigrate: { context in // Logic to perform the migration of V2 schema let tests = try context.fetch(FetchDescriptor<ModelSchemaV2.Test1>()) // Do the migration operation.... } try context.save() } ) static let migrateV2toV3 = MigrationStage.lightweight( fromVersion: ModelSchemaV2.self, toVersion: ModelSchemaV3.self ) static var stages: [MigrationStage] { // Migration stage that will be performed [migrateV1toV2, migrateV2toV3] } } Please let me know if you need more details to reproduce it.
Replies
Boosts
Views
Activity
Oct ’24
Reply to onAppear is called when the view hasn't appeared
Seems the bug is fixed in Xcode 13.2 beta (13C5066c) and iOS 15.2. In my app I use three tabs. My app starts with tab 0. If I go to tab 1, the on onAppear-Method gets called. Last, I go to tab 2 but the onAppear-Method gets called twice. But the method should only called once.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21