Nicolas Duval
Nicolas Duval

Reputation: 167

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 !

Upvotes: 0

Views: 804

Answers (2)

Georg Tuparev
Georg Tuparev

Reputation: 441

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.

Upvotes: 1

Anthony Kong
Anthony Kong

Reputation: 40634

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

Upvotes: 1

Related Questions