This specific warning usually happens because your class is "isolated" to the Main Actor (the UI thread), but the protocol doesn't guarantee that. When you try to assign the delegate, Swift worries that a background thread might try to call those methods, causing a data race.
Here is a concise, punchy Reddit post to get the community's take on the "new" way to handle this.
Title: How are you handling @MainActor Delegates and Protocols in Swift 6?
Post Body:
I'm hitting a wall with the Delegate pattern under strict concurrency.
The Setup: I have a Manager (non-isolated) and a ViewController (isolated to @MainActor). When I try to set the delegate, or call delegate methods, I get isolation mismatch warnings.
The Question: What is the "correct" architectural way to handle this now?
-
Do you mark the Protocol itself as
@MainActor? -
Do you keep the protocol non-isolated and use
Task { @MainActor in ... }inside the Manager? -
Or is it time to ditch delegates for
AsyncSequenceorObservation?
Curious how everyone is satisfying the compiler without nesting Task blocks everywhere.