nerdintown
nerdintown

Reputation: 115

didSet Not Observing Static Variables

I'm trying to use didSet on a static observed property but it's not running the if-else statement in the didSet. Here is the code:

    static var isCorrect: Bool = false {
    didSet {
        if isCorrect {
            ViewController.theViewController.checkbox.image = UIImage(named: "tick")
        } else {
            ViewController.theViewController.checkbox.image = nil
        }
    }
}

static var theViewController = ViewController()

It is all in a class called ViewController. I'm changing the isCorrect variable in another view controller class and dismissing it after that but it doesn't seem to work.

The checkbox property used there is a variable of type UIImageView.

Am I doing anything wrong? If I am then what is the right way?

Upvotes: 1

Views: 141

Answers (0)

Related Questions