I am building a Quiz and I have a struct with 4 Variables which are countries.
I have around 15 View Controllers with 4 buttons, each button represents one Country and increments the score by 1.
Now at the end of the Quiz, I want to display the country with the highest score and make it open a new View Controller.
import Foundation
var ukScore = 0
var greeceScore = 0
var italyScore = 0
var austriaScore = 0
var finalCountry = ""
struct QuizScore {
func ukScoreIncrement() {
ukScore += 1
}
func greeceScoreIncrement() {
greeceScore += 1
}
func italyScoreIncrement() {
italyScore += 1
}
func austriaScoreIncrement() {
austriaScore += 1
}
func getFinalScore(){
if ukScore == max(ukScore, greeceScore, italyScore, austriaScore) {
finalCountry = "Uk"
} else if greeceScore == max(ukScore, greeceScore, italyScore, austriaScore) {
finalCountry = "greece"
} else if italyScore == max(ukScore, greeceScore, italyScore, austriaScore) {
finalCountry = "italy"
} else if austriaScore == max(ukScore, greeceScore, italyScore, austriaScore) {
finalCountry = "austria"
}
}
}
`
The idea is to figure out which country wins, and then pass the string to my last class which would then prepare the next segue depending on the winning country.