There is an article about this on swift.org: Sendable Metatypes.
You need to add a SendableMetatype
constraint. You can add it for all P
like this:
protocol P: Sendable {
associatedtype State: P2 & SendableMetatype
}
Or you can add it for all Foo
like this:
final class Foo<T: P> where T.State: SendableMetatype {
Or you can add it for just that init
like this:
init(initialState: T.State) where T.State: SendableMetatype {
I think the use of SendableMetatype
should back-deploy (it is a marker protocol with no constraints and the documentation says it is available since iOS 8, macOS 10.10, etc.). However, Xcodes older than 26 beta 1 don't know it. So you may also want to add this definition:
#if compiler(<6.2)
public typealias SendableMetatype = Any
#endif
You can find more discussion here: Issues with SE-0470: Global-actor isolated conformances