Overview
A type that conforms to the
GlobalActorprotocol and is marked with the@globalActorattribute can be used as a custom attribute. Such types are called global actor types, and can be applied to any declaration to specify that such types are isolated to that global actor type. When using such a declaration from another actor (or from nonisolated code), synchronization is performed through the shared actor instance to ensure mutually-exclusive access to the declaration.
Is the conformance to GlobalActor mandatory?
I ask because these both compile, and seem to work.
Conforming to GlobalActor:
@globalActor
actor A: GlobalActor {
static let shared: A = .init()
private init () {}
}
Without conforming to GlobalActor:
@globalActor
actor A {
static let shared: A = .init()
private init () {}
}
What is the difference? ![]()