This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct CountryModel: Codable { | |
| let country: String | |
| let cases: Int | |
| let todayCases: Int | |
| let deaths: Int | |
| let todayDeaths: Int | |
| let recovered: Int | |
| let todayRecovered: Int | |
| let countryInfo: CountryInfo | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do { | |
| let country = try decoder.decode([CountryModel].self, from: data) | |
| for i in 0..<country.count { | |
| self.countryNames.append(country[i].country) | |
| self.flags.append(country[i].countryInfo.flag) | |
| self.totalCaseList.append(country[i].cases) | |
| self.totalDeathList.append(country[i].deaths) | |
| self.totalRecoveredList.append(country[i].recovered) | |
| self.dailyCaseList.append(country[i].todayCases) | |
| self.dailyDeathList.append(country[i].todayDeaths) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
| chosenCountryName = countryNames[indexPath.row] | |
| chosenFlagUrl = flags[indexPath.row] | |
| chosenTotalCases = "\(totalCaseList[indexPath.row])" | |
| chosenTotalDeathts = "\(totalDeathList[indexPath.row])" | |
| chosenTotalRecovered = "\(totalRecoveredList[indexPath.row])" | |
| chosenDailyCases = "\(dailyCaseList[indexPath.row])" | |
| chosenDailyDeaths = "\(dailyDeathList[indexPath.row])" | |
| chosenDailyRecovered = "\(dailyRecoveredList[indexPath.row])" | |
| performSegue(withIdentifier: "showCountryDetail", sender: self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| guard let flagUrl = URL(string: flagUrl) else { | |
| print("Flag Error") | |
| return | |
| } | |
| let task = URLSession.shared.dataTask(with: flagUrl) { (data, response, error) in | |
| if let data = data { | |
| let downloadedImage = UIImage(data: data) | |
| DispatchQueue.main.async { | |
| self.flagImage.image = downloadedImage | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class CountryViewController: UIViewController { | |
| @IBOutlet weak var flagImage: UIImageView! | |
| @IBOutlet weak var countryName: UILabel! | |
| @IBOutlet weak var dailyConfirmed: UILabel! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var tableView: UITableView! | |
| var countryNames: [String] = [] | |
| var flags: [String] = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var tableView: UITableView! | |
| var countryNames: [String] = [] | |
| var flags: [String] = [] | |
| var totalCaseList: [Int] = [] | |
| var totalDeathList: [Int] = [] |