RezaA
(Reza)
November 7, 2025, 12:43pm
1
In Xcode 26.1, for a project with “Swift Language Version” set to swift6 I am getting for the following code I get errors:
Error1: Main actor-isolated initializer 'init(title:action:keyEquivalent:)' has different actor isolation from nonisolated overridden declaration
Error2: Main actor-isolated initializer 'init(coder:)' has different actor isolation from nonisolated overridden declaration
@MainActor class MenuItem: NSMenuItem { // error1
var userInfo: [String : Any] = [:]
init(label: String, action: Selector?, target: AnyObject?, userInfo: [String : Any]) {
self.userInfo = userInfo
super.init(title: label, action: action, keyEquivalent: "")
}
required init(coder decoder: NSCoder) { // error2
super.init(coder: decoder)
}
}
I have now just discovered that if I set “Default Actor Isolation” to none isolated, then the error goes away, which seems very odd. Any help or suggestions.
RezaA
(Reza)
November 7, 2025, 5:08pm
3
I had tried removing @MainActor that still gives the same error. If I mark the class with nonisolated, the error goes away.
However I would like to know why this is happening. Is it a bug or some kind of language feature. Interestingly if I subclass NSView it behaves as expected.
Jon_Shier
(Jon Shier)
November 7, 2025, 5:18pm
4
Sounds like you have MainActor default isolation turned on.
tera
November 7, 2025, 5:31pm
5
Sounds like you have MainActor default isolation turned on.
And if you want to keep it that way – mark the class nonisolated to opt-out.
RezaA
(Reza)
November 7, 2025, 5:40pm
6
Yes, the MainActor default isolation is on, and as I mentioned above, if I mark the class with noneisolated the error goes away.
What I don’t understand why this happens for NSMenuItem, and not for other Appkit classes that I tried such, as NSView.
tera
November 7, 2025, 5:45pm
7
Apple has marked NSView with NS_SWIFT_UI_ACTOR and didn't do that (yet?) with NSMenuItem.
In this particular case you may find these two properties useful for your purposes:
open var tag: Int
open var representedObject: Any?
instead of subclassing.
RezaA
(Reza)
November 7, 2025, 6:15pm
8
Thanks for the explanation. I will look into it.