Search code examples
macosswiftxcode6nsviewcontroller

Swift NSViewController


I'm new to cococa and swift, and I'm tring to create a custom ViewController.

class StatusUpdate : NSViewController {

  @IBOutlet var StatusView: NSView!
  @IBOutlet var eventsFoundCell: NSTextFieldCell!

  @IBAction func update(sender: AnyObject) {
      StatusView.hidden = false
      eventsFoundCell.stringValue = "A"
  }
}

The code as shown above is working as you would expect it. But what I tring to do is to add an other function to that class like :

  func otherUpdate() {  
    eventsFoundCell.stringValue = "B"
  }

In order to update the stringValue of the eventsFoundCell variable. So I could call it in an other class :

var update = StatusUpdate()
update.otherUpadte()

When calling update.otherUpadte() with in n other class,

I'm always getting an error like :

Thread1: EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP, subcode=0x0)

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

Any idea on show I could do this ?

Thank you !


Solution

  • It is because in this line

     var update = StatusUpdate()
    

    You are creating a new instance of StatusUpdate. The variable StatusView is not bound to any NSView