Swift protocols and the main actor
[]
Swift by Sundell
In Swift, the @MainActor attribute can be used to associate a given type, function, or value with the global main actor, which essentially makes any such code operate on the enclosing app’s main thread.
Just like concrete types, a Swift protocol can be fully isolated to the main actor, which means that all of its members (which in the case of a protocol are its list of requirements, and any extensions we’ve added) in turn also become main actor isolated.
But what if we’re looking to make an actual actor type conform to our ErrorPresenter protocol?
So does that mean that we should never fully associate any protocol with the main actor, and instead only annotate individual requirements with @MainActor ?
My personal approach is to avoid isolating entire protocols unless they are clearly only ever going to be adopted by main actor bound types.