0

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 !

Nicolas Duval
  • 167
  • 1
  • 9

2 Answers2

1

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

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
1

You already got the answer, so this is recommendation only. It will make your Cocoa life way easier if you follow well established conventions. So, instead of:

@IBOutlet var StatusView: NSView!

you should write

@IBOutlet var statusView: NSView!

There are many cases in Cocoa where proper capitalisation (and style in general) are assumed in order for the frameworks to work.

Georg Tuparev
  • 441
  • 2
  • 6
  • 11