Mercurial > public > geoquiz
comparison GeoQuiz/Controllers/CityGameController.swift @ 34:6ec51a4ca897
fix crash when asking new questions
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sat, 12 Nov 2022 14:23:05 +0100 |
parents | 6d574bd1644f |
children |
comparison
equal
deleted
inserted
replaced
33:6d574bd1644f | 34:6ec51a4ca897 |
---|---|
19 | 19 |
20 @Published var userChoices = [String: T]() | 20 @Published var userChoices = [String: T]() |
21 @Published var userScore = 0 | 21 @Published var userScore = 0 |
22 @Published var userLives = 3 | 22 @Published var userLives = 3 |
23 | 23 |
24 @Published var correctAnswer = (key: String(), value: T(country: String(), lat: Double(), lon: Double())) | 24 @Published var correctAnswer = (key: "", value: T(country: "", lat: Double(), lon: Double())) |
25 @Published var correctAnswers = [String: T]() | 25 @Published var correctAnswers = [String: T]() |
26 @Published var wrongAnswers = [String: T]() | 26 @Published var wrongAnswers = [String: T]() |
27 | 27 |
28 // Alerts | 28 // Alerts |
29 @Published var alertTitle = String() | 29 @Published var alertTitle = String() |
43 init() { | 43 init() { |
44 let data: CityModel = Bundle.main.decode("cities.json") | 44 let data: CityModel = Bundle.main.decode("cities.json") |
45 let shuffledCities = data.cities.shuffled() | 45 let shuffledCities = data.cities.shuffled() |
46 var cities = [String: T]() | 46 var cities = [String: T]() |
47 | 47 |
48 for _ in 1...10 { | 48 for _ in 1...100 { |
49 let countryNames = cities.map { $0.value.country } | 49 let countryNames = cities.map { $0.value.country } |
50 let city = shuffledCities.first(where: { | 50 let city = shuffledCities.first(where: { |
51 !countryNames.contains($0.value.country) | 51 !countryNames.contains($0.value.country) |
52 })! | 52 })! |
53 | 53 |