Currently when migrating code to concurrency code that should be isolated to GlobalActor
can be marked @preconcurrency @GlobalActor
to avoid breaking existing code.
@globalActor
actor MyGlobalActor: GlobalActor {
static let shared = MyGlobalActor()
}
@preconcurrency
@MyGlobalActor
func isolatedFunc() { }
func existingUsage() {
// doesn't break
isolatedFunc()
}
Is there any similar approach that can be used with classes that can be converted to actor?
@preconcurrency // doesn't work
actor MyClass: NSObject {
@preconcurrency // doesn't work
var message: String
}
@preconcurrency // doesn't work
func existingUsage(obj: MyClass) {
// breaks
print(obj.message)
}
The only thing that I have found is the assumeisolated(_:file:line:)
API. But that requires change in every call site making it not ideal for existing code that want to migrate.