December 2018
Intermediate to advanced
414 pages
10h 19m
English
The model layer still contains the Question structure and the QuestionController class. We can keep those components as they are. The ViewModel pattern is used to bind the model layer to the view layer, and its responsibility is to abstract the details of rendering the model into a view:
// Question.swiftenum BooleanAnswer: String { case `true` case `false`}struct Question { let question: String let answer: BooleanAnswer}extension Question { func isGoodAnswer(result: String?) -> Bool { return result == answer.rawValue }}// QuestionController.swiftclass QuestionController { private var questions = [Question]() // Load the questions from memory or disk func load() { /* load from disk, memory or else */ } // Get the next question, if available ...
Read now
Unlock full access