Why does custom NSMenuItem (MyNSMenuItem) perform action sender still to be NSMenuItem?

61 Views Asked by At

I have create a new NSMenuItem class shows in the following:

class FilerNSMenuItem: NSMenuItem {
    private var defaultFileExtension: String = ""

    var fileExtension: String {
        get { return defaultFileExtension }
        set { defaultFileExtension = newValue }
    }
}

And I create a menu item using following code:

item = FilerNSMenuItem(title: title, action: #selector(SomeActions(_:)), keyEquivalent: "")
menuItem.submenu?.items.append(item)

The SomeActions is defined in the following:

@objc func SomeActions(_ sender: FilerNSMenuItem) {
    if sender.fileExtension != "" {
        ...
    }
}

However, when I tap the menu item, and the error occurred in the SomeAction, the sender here is still NSMenuItem not FilerNSMenuItem and error says Thread 3: EXC_BAD_ACCESS.

How can I deal with this problem so that the sender is FilerNSMenuItem not NSMenuItem. Thank you.

0

There are 0 best solutions below