The evolution changed the ability to make a lot of default value properties require to instead be initialized inside an initializer. It gives the following example clarifying why, and it makes sense to me why this wouldn't work:
@MainActor func getStatus() -> Int { /* ... */ }
@PIDActor func genPID() -> ProcessID { /* ... */ }
class Process {
@MainActor var status: Int = getStatus()
@PIDActor var pid: ProcessID = genPID()
init() {} // Problem: what is the isolation of this init?
}
However, I'm in a situation where I have a lot of code that is much more like this and getting the errors:
@MainActor func getStatus() -> Int { /* ... */ }
@MainActor func genPID() -> ProcessID { /* ... */ }
@MainActor
class Process {
@MainActor var status: Int = getStatus()
@MainActor var pid: ProcessID = genPID()
init() {} // shouldn't this init be restricted to @MainActor through the class's declaration?
init(alternate: Bool) {} // I'd rather not have to copy all my properties' inits here too
init(alternate2: Bool) {} // nor here
}
I'd even be fine restricting the init to @MainActor explicitly. I see no reason why, in this scenario, I should have to move all my default properties into the initializer, when the entirety of the class is restricted to the @MainActor.
It might be worth mentioning that most of the code like this is UI, so being able to constrain to the MainActor is a godsend.
I apologize if I'm missing something obvious. I just feel like the Swift compiler should be smart enough to recognize that this class's properties need to be synthesized on the same actor as the rest of the class, especially when I am explicit about it.
I have not. To clarify, by trying the latest toolchain off main, do you mean to clone, compile, then set Xcode to use that toolchain instead of what's included? Cuz I'm unsure how to do that (but am more than capable of finding some guide)
Also, I'm unsure how to do this as well and would be unsure of where to look for how to do so:
Does activating the global @MainActor isolation using -warn-concurrency help at all here?
I'm having this exact same issue. Currently sitting with about 800+ of these warnings and moving all of the property setting to the init seems a bit excessive. We've thought about moving all of the properties to lazy private(set) var.
I can't find any discussions about the reverted change. Is there any indication as to when we will see these changes? Will it be a hot fix to 5.6 or will we have to wait for 5.7 to rid ourselves of these warnings?
I'm also curious as to the "important workflows" that were broken mentioned in the PR.
If anyone has any insight to this, would be greatly appreciated!