The main class of my model is Concentration with a property called flipCount
class Concentration {
@objc var flipCount = 0
In My ViewController I have an @IBOutlet to a UILabel called flipCountLabel
class ViewController: UIViewController {
lazy var game = Concentration(numberOfPairsOfCards: self.cardButtons.count / 2)
@IBOutlet weak var flipCountLabel: UILabel!
...
I want to update the text in flipCountLabel when flipCount changes. I am trying to do this by placing a call to the observe method of UIViewController in my ViewController's viewDidLoad method. There are a few observe methods. I don't know which one is right and cannot find an example for how to what to fill in the variables with.
I have tried to use self.observe like
self.observe(KeyPath<Concentration,Int>(game, "flipCount"), changeHandler: {
self.flipCountLabel.text = "Flip Count: \(flipCount)"
})
I am trying to update the ViewControllers flipCountLabel.text every time game.flipCount is updated. I think this is kvo?