Model Container Sendable Throwing Error in Swift 6

Hi all,

I just wanted to ask how people were using ModelActor with the Swift 6 language mode enabled. My current implementation involves passing the ModelContainer to my ModelActor, which worked in Sonoma and previous betas of Sequoia, however in the current Beta 3, I get this error:

"Sending 'self.modelContext.container' risks causing data races"

I am a bit confused by this, as from what I understand, ModelContainer conforms to Sendable, so ideally this error should not be thrown. Is this a bug in Beta 3?

Thanks in advance.

Answered by ChristophKaser in 795695022

Yes, this is a bug in Beta 3. There is a similar discussion in the swift forums: https://forums.swift.org/t/why-does-sending-a-sendable-value-risk-causing-data-races/73074

Accepted Answer

Yes, this is a bug in Beta 3. There is a similar discussion in the swift forums: https://forums.swift.org/t/why-does-sending-a-sendable-value-risk-causing-data-races/73074

UPDATE: It has not been fixed in Xcode 16 Beta 4; the error is still being thrown. Will continue to run the Swift 5 language mode until it has been resolved in a future beta.

You could create a constant variable and pass that

let container = self.modelContext.container
someFunc(container: container)
Model Container Sendable Throwing Error in Swift 6
 
 
Q