Refined actor initialization and deinitialization
About 1 min
Refined actor initialization and deinitialization 관련
HACKING WITH SWIFT
What's new in Swift?
Refined actor initialization and deinitialization | Changes in Swift 5.10
Refined actor initialization and deinitialization
Available from Swift 5.10
SE-0327 (apple/swift-evolution
) adds some clarifications about how state inside actors is created and destroyed, and also relaxes some rules that were overly restrictive.
This proposal contains a number of small, specific changes to actors. For example, Swift will now automatically make actors with an async initializer move to the actor's executor when all its properties are initialized.
In code, it means the two print()
calls shown below might execute on entirely different threads:
actor Actor {
var name: String
init(name: String) async {
print(name)
self.name = name
print(name)
}
}
let actor = await Actor(name: "Margot")
This means the code has a potential suspension directly after the name
property is set.
Other Changes in Swift 5.10
Data races are now clearly diagnosed | Changes in Swift 5.10
Data races are now clearly diagnosed
Allow Protocols to be Nested in Non-Generic Contexts | Changes in Swift 5.10
Allow Protocols to be Nested in Non-Generic Contexts
Deprecate @UIApplicationMain and @NSApplicationMain | Changes in Swift 5.10
Deprecate @UIApplicationMain and @NSApplicationMain