I´m making a mathematical quiz game. In the game the user selects a unit and then the game ask questions about exercises of this unit.
The classes I have are:
ViewController
UnitSelector - is responsible for inform the unit that the user has selected
Unit01…to…Unit20 - are responsible for return randomly one exercise of the unit
And lots of exercises
class UnitSelector {
var unit: Int!
init(unit: Int) {
self.unit = unit
}
func getUnitClass() -> Any? {
switch unit {
case 0:
return Unit01()
case 1:
return Unit02()
// all the other cases
case 19:
return Unit20()
default:
return nil
}
}
}
class GameViewController: UIViewController {
override func viewDidLoad() {
// more code
unitSelector = UnitSelector(unit: selectedUnit)
unitClass = unitSelector.getUnitClass()
let question = unitClass.giveMeQuestion()
}
// all the other code
}
// all the Units are like this one
class UnitXX {
// vars
func giveMeQuestion() -> String {
// code
return "Question"
}
}
The problem is that I don´t know how to solve this situation: I´ve divided it in Units and each unit has its own exercises. I´ll have about 20 Units and in each unit about 5 exercises. In the controller the unitClass´s type is Any and I need to have the class that the UnitSelector.getUnitClass returns, Unit01()...Unit20(). I don´t know if the logic that I followed is the correct, so if someone can help me...
Thanks!!