SwiftData SchemaMigrationPlan and VersionedSchema not Sendable

I am writing a new app from scratch using swift6 and SwiftData, and so far have been pretty happy not to run into errors or warnings about unsafe code.

Today I started to add Schema versioning to my SwiftData model and was surprised to get told by the compiler that MigrationStage and Schema.Version are not Sendable. This was simply on the standard (as per documentation examples) declarations, and not related to any concurrent use of the types or instances. As a fix it was suggesting making the import SwiftData @preconcurrency, which seemed to be a rather odd recommendation, akin to sweeping the problem under the carpet.

A Google turned up a June'24 post (see below) on the Apple Discussions forum, where a DTS engineer suggested that the error was spurious, and there should be no reason these types should not be Sendable. Their suggestion to solve the problem was that one should add:

extension MigrationStage: @unchecked @retroactive Sendable { }
extension Schema.Version: @unchecked @retroactive Sendable { }

The suggestion works, but my question is, is that an acceptable solution to this issue, or could it lead to future problems ?

If it is a canonical solution, I wonder why if DTS knew this in June, why isn't it already incorporated in iOS18/macOS15 ?

Cheers
Guy

2 Likes

why isn't it already incorporated in iOS18/macOS15 ?

I think it’d be better to ask Ziqiao directly on that DevForums thread you uncovered.

For context, SwiftData is very much an Apple API, one that’s only available on Apple platforms, and thus you’re more likely to get help in Apple Developer Forums rather than here. Swift Forums tends to focus on Swift the language, and its associated cross-platform libraries.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

… A different DTSer (-:

Thanks Quinn