cocoaswiftxcode6iboutletnswindowcontroller

Use NSToolBar Outlet xcode 6 and Storyboard?


I am trying to add an outlet into my viewcontroller for a toolbar item in my window controller. I have tried playing around with first responder and bindings but have not been able to find any solutions.

A similar question that was answered provided some insight but no one has mentioned anything about IBOutlets other than still asking how to add them in the comments. The answer has been accepted so i am assuming no one will add to it.

How to use NSToolBar in Xcode 6 and Storyboard?

Incase my question is unclear at all, i would like to be able to add this to my storyboard program

@IBOutlet weak var Mytoolbar: NSToolbarItem!

func enabletoolbar()
{
    Mytoolbar.action = "FunctionIn.ViewController.swift"
    Mytoolbar.enabled = true
}

Solution

  • i ended up doing this in my view controller which seems to work

    override func viewDidLayout() {
        var x = self.view.window?.toolbar?.items[1].label
        println(x)
        if(self.view.window?.toolbar?.items[0].label! != "Check")
        {
            toobarediting()
        }
        println("didlay")
    }
    
    func toobarediting() {
        self.view.window?.toolbar?.insertItemWithItemIdentifier("Check", atIndex: 0)
    }
    
    func toolbarcheck(functiontoset: Selector) {
        var y = self.view.window?.toolbar?.items[0] as NSToolbarItem
        y.action = functiontoset
        if(functiontoset != nil)
        {
            y.enabled = true
        }
    }
    

    It seems to allow me to make the tool bar button clickable/unclickable when ever i require it to change it just seems so much more bulky and error prone than

    myitem.enable = fale 
    myitem.action = nil
    

    is this really the best way for a storyboard based application in osx?