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.