Xcode 26.1 can't subclass NSMenuItem

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.

just remove @MainActor

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.

Sounds like you have MainActor default isolation turned on.

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.

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.

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.

Thanks for the explanation. I will look into it.