Error message when opening a SwiftData ModelContainer

I'm seeing these errors in the console when calling ModelContainer(for:migrationPlan:configurations) for iOS 18:

error: Attempting to retrieve an NSManagedObjectModel version checksum while the model is still editable. This may result in an unstable verison checksum. Add model to NSPersistentStoreCoordinator and try again.

CoreData: error: Attempting to retrieve an NSManagedObjectModel version checksum while the model is still editable. This may result in an unstable verison checksum. Add model to NSPersistentStoreCoordinator and try again.

Is this anything to be concerned about?

(Side note: "version" is misspelled in "verison checksum")

Answered by DTS Engineer in 809765022

Thanks for your info, @Ghostwalk. I reproduced the error – As the message says, it is triggered because SwiftData needs to access the version checksum before the model is loaded to the Core Data stack. I am pretty sure that has no harm on apps. Meanwhile, I don't see anything apps can do to eliminate it, and so would suggest that you file a feedback report to hopefully get attentions from the SwiftData team – If you do so, please your report ID here for folks to track. Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I don't see the error something to be concerned because it doesn't bring any real issue, but do you have a reproducible case? If you have and don't mind to share the details (the code snippet, the version of system and Xcode, etc), I'd be interested in taking a closer look.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

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.

Thanks for your info, @Ghostwalk. I reproduced the error – As the message says, it is triggered because SwiftData needs to access the version checksum before the model is loaded to the Core Data stack. I am pretty sure that has no harm on apps. Meanwhile, I don't see anything apps can do to eliminate it, and so would suggest that you file a feedback report to hopefully get attentions from the SwiftData team – If you do so, please your report ID here for folks to track. Thanks.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

I filed a bug FB15592048 for it.

Error message when opening a SwiftData ModelContainer
 
 
Q