Skip to content

Instantly share code, notes, and snippets.

View hgunes's full-sized avatar
🏠
Working from home

Harun Güneş hgunes

🏠
Working from home
View GitHub Profile
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
}
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)
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)
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
}
import UIKit
class CountryViewController: UIViewController {
@IBOutlet weak var flagImage: UIImageView!
@IBOutlet weak var countryName: UILabel!
@IBOutlet weak var dailyConfirmed: UILabel!
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var countryNames: [String] = []
var flags: [String] = []
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
var countryNames: [String] = []
var flags: [String] = []
var totalCaseList: [Int] = []
var totalDeathList: [Int] = []