I noticed a change from previous betas when I attempted to compile my code with Xcode 16 beta 5.
If I have a class that is MainActor isolated, and it overrides init(), it looks like this init is always considered nonisolated now, even for a MainActor isolated class.
This was not the case before.
For example, I have a class that inherits from NSScroller. It defines a default initializer init()
which calls the designated initializer - super.init(frame:CGRect())
. This is apparently not allowed right now. If that's the case, how can one even default-initialize a class??? It also doesn't let me initialize other properties, since everything is MainActor isolated.
Here's an abbreviated example.
class MyCustomScroller : NSScroller {
init () {
super.init(frame: CGRect())
scrollerStyle = .overlay
alphaValue = 0
}
}
This was allowed in prior betas. However, in beta 5, all 3 lines of my init generates an error such as: Call to main actor-isolated initializer 'init(frame:)' in a synchronous nonisolated context
or Main actor-isolated property 'scrollerStyle' can not be mutated from a nonisolated context
Is it just no longer possible to default-initialize MainActor classes, such as NSViews, now?
The first line is particularly problematic because if I change it to just call super.init() then I get this error instead:
Must call a designated initializer of the superclass 'NSScroller'
You must call the designated initializer ... oh wait, we won't let you. Too bad.