-1

This code doesn't work.

import Cocoa

class ViewController: NSViewController {

    @IBOutlet weak var textField: NSTextField!

    var guessScore : Int

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override init(){
        super.init()
        guessScore = 1
    }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Z.S.
  • 39
  • 1
  • 9

2 Answers2

0

before calling super.init(), all your properties must be initialized (they have to have some 'default' value), Please read apple docs.

override init(){
    guessScore = 1
    super.init()
}
user3441734
  • 16,722
  • 2
  • 40
  • 59
0

Your code produces: enter image description here

So you may want to simply follow the instructions given by Xcode and override the designated initializer:

var guessScore: Int

override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    guessScore = 1
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}

required init?(coder: NSCoder) {
    guessScore = 1
    super.init(coder: coder)
}

Or directly without any initializer, provide a default value:

var guessScore: Int = 1
Cœur
  • 37,241
  • 25
  • 195
  • 267