1

I'm currently working on a menubar app and I'm trying to implement a NSTextField or NSSecureTextField. This is what I do to add NSMenuItems

let menu = NSMenu()
menu.addItem(NSMenuItem(title: "Save Test Data", action: #selector(AppDelegate.saveData), keyEquivalent: ""))

but trying to add a NSTextField like this:

menu.addItem(NSTextField)

brings this Error:

Cannot convert value of type '(NSTextField).Type'(aka 'NSTextField.Type') to expected argument type 'NSMenuItem'

But how should I implement a NSTextField using NSMenuItem?

1 Answer 1

3

You cannot add other elements as NSMenuItem to a menu directly.

To implement a text field you have wrap it in a custom NSView and assign the view to the view property of the menu item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.