1

I have a simple Swift cocoa application. The main window contains:

  • a toolbar with some Image Toolbar Items
  • a NSViewController (named ViewController)

In ViewController I have implemented:

func validateToolbarItem(_ item: NSToolbarItem) -> Bool

to enable the buttons as per my requirements.

Unfortunately, the validateToolbarItem is never called.

In an another Objective-c application I have exactly the same scenario and the function:

-(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem

is properly called.

How do I sort this problem out? What do I miss in swift?

Thks.

Fab
  • 1,468
  • 1
  • 16
  • 37
  • Possible duplicate of [How to implement validateToolbarItem(\_:)?](https://stackoverflow.com/questions/44596480/how-to-implement-validatetoolbaritem) – Willeke Apr 13 '19 at 21:43

1 Answers1

2

I eventually sorted this out.

The ViewController has to implement NSToolbarItemValidation protocol:

class ViewController: NSViewController, ..., NSToolbarItemValidation {

    ....

    func validateToolbarItem(_ item: NSToolbarItem) -> Bool {

        return true or false
    }
}

Problem is that when I tested this the first time it did't work. I had to restart Xcode to make it working.

Fab
  • 1,468
  • 1
  • 16
  • 37