[Stanford Assignment I] How do I correctly track and update the Concentration game's flipCount in an MVC-appropriate manner?

Total beginner here working on Assignment I of Stanford's Developing iOS 11 Apps with Swift course.

I managed to do all the required tasks 1 - 6 but am struggling with:

8. Tracking the flip count almost certainly does not belong in your Controller in a proper MVC architecture. Fix that.


We have the controller ViewControl.swift and we have the model Concentration.swift files.


In the lecture, flipCount was implemented inside ViewControl.swift as such:


var flipCount = 0 {
     didSet {
          flipsLabel.text = "Flips: \(flipCount)"
     }
}


Now if I simply moved that over to the model file Concentration.swift, I get an error that flipsLabel is unresolved there - which makes sense, because as I understand it, the controller should be UI-independent, and flipsLabel is clearly a UI element.


But does that mean that if I track flipCount in the model, I can't use didSet at all, and instead have to do

flipsLabel.text = "Flips: \(game.flipCount)"

where game is my Concentration class object in the controller ViewController.swift whenever I do something that changes flipsCount?


I'm confused how to separate these things out in the correct and most elegant way.

You have a VC with flipsLabel IBOutlet

You have a model (MyModel) with flipCount var.


in Model, create a flipsLabel property

var flipsText = ""


var flipCount = 0 {
     didSet {
          flipsText = "Flips: \(flipCount)"
     }
}

you may have a func

func incrementFlip() {
     flipCount += 1
}


In the VC, you created an instance of the model

var myModel = MyModel() // may be some parameters here


I suppose the flipCount changes when you click a button for instance.


In the IBAction, you have

@IBAction func Button(sender: UIButton) {
   myModel.incrementFlip()
   flipsLabel.text = myModel.flipsText
}
[Stanford Assignment I] How do I correctly track and update the Concentration game's flipCount in an MVC-appropriate manner?
 
 
Q