Trying to pass json data to labels

hi there!

im making a covid app that take data of the number of cases in my city, i made a json file and parse data
i passed the data to a table view like i wanted bur the thing is that in the casosViewcontroller i cant pass the data. is nil

Git: https://github.com/CarlosCardonaM/covidGto

struct CasosData: Codable {

var fecha:String
var semaforo:String
var casosConfirmados:Int
var casosEnInvestigacion:Int
var casosDescartados:Int
var defunciones:Int
var casosRecuperados:Int
var casosDeTransmisionComunitaria:Int

}

public class DataLoader {

@Published var casosData = [CasosData]()

init() {
    load()
}
func load() {
    if let fileLocation = Bundle.main.url(forResource: "CoronavirusGuanajuato", withExtension: "json") {
        
        // Do catch
        do {
            let data = try Data(contentsOf: fileLocation)
            let jsonDecoder = JSONDecoder()
            let dataFromJson = try jsonDecoder.decode([CasosData].self, from: data)
            
            self.casosData = dataFromJson
        }
        catch {
            print(error)
        }
    }
}

}

class ViewController: UIViewController {

@IBOutlet weak var imagenGto: UIImageView!
@IBOutlet weak var datosButton: UIButton!
@IBOutlet weak var infoButton: UIButton!


override func viewDidLoad() {
    super.viewDidLoad()
    title = "COVID-19 Gto"
    view.backgroundColor = .white
    
    imagenGto.layer.borderWidth = 1
    imagenGto.layer.masksToBounds = false
    imagenGto.layer.borderColor = UIColor.black.cgColor
    imagenGto.layer.cornerRadius = imagenGto.frame.height / 2
    imagenGto.clipsToBounds = true
    
    datosButton.layer.cornerRadius = 10
    
}

}

class DatosViewController: UIViewController {

let casosData = DataLoader().casosData
var casos:CasosData?


@IBOutlet weak var fechasTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    fechasTableView.delegate = self
    fechasTableView.dataSource = self
}

}

// MARK: - TableView delegate and Datasource Methods
extension DatosViewController: UITableViewDelegate, UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return casosData.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "fechasCell", for: indexPath)
    cell.textLabel?.text = casosData[indexPath.row].fecha
    cell.textLabel?.font = .boldSystemFont(ofSize: 15 )
    
    if casosData[indexPath.row].semaforo == "Rojo" {
        cell.textLabel?.textColor = .red
    }
    else if casosData[indexPath.row].semaforo == "Naranja" {
        cell.textLabel?.textColor = .orange
    }
    else if casosData[indexPath.row].semaforo == "Amarillo" {
        cell.textLabel?.textColor = .yellow
    }
    else {
        cell.textLabel?.textColor = .green
    }
    return cell
    
}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
    }

}

class CasosViewController: UIViewController {

var casosData = DataLoader().casosData
var casos:CasosData?





@IBOutlet weak var casosConfirmadosNumber: UILabel!

@IBOutlet weak var casosEnInvestigacionNumber: UILabel!

@IBOutlet weak var casosDescartadosNumber: UILabel!

@IBOutlet weak var defuncionesNumber: UILabel!

@IBOutlet weak var casosRecuperadosNumber: UILabel!

@IBOutlet weak var casosDeTransmicionNumber: UILabel!

@IBOutlet weak var colorSemaforoImageView: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    
     // passing the number of cases labels from the json file
    
    casosConfirmadosNumber.text = String(describing: casos?.casosConfirmados)
    casosDescartadosNumber.text = String(describing: casos?.casosDescartados)
    casosEnInvestigacionNumber.text = String(describing: casos?.casosEnInvestigacion)
    defuncionesNumber.text = String(describing: casos?.defunciones)
    casosRecuperadosNumber.text = String(describing: casos?.casosRecuperados)
    casosDeTransmicionNumber.text = String(describing: casos?.casosDeTransmisionComunitaria)
    
}

}

JSON FILE

[
{
“fecha”: “6 de Julio del 2020”,
“semaforo”: “Rojo”,
“casosConfirmados”: 10115,
“casosEnInvestigacion”: 2621,
“casosDescartados”: 19048,
“defunciones”: 611,
“casosRecuperados”: 3177,
“casosDeTransmisionComunitaria”: 9960
},
{
“fecha”: “7 de Julio del 2020”,
“semaforo”: “Verde”,
“casosConfirmados”: 10568,
“casosEnInvestigacion”: 2521,
“casosDescartados”: 19693,
“defunciones”: 649,
“casosRecuperados”: 4394,
“casosDeTransmisionComunitaria”: 10413
}
]

it would be better to post a screenshot of the error instead

Hola Carlos. Finalmente has podido lograr que se vea la data de Json en Labels? Yo estoy intentando hacer algo parecido.

Si! Ya no recuerdo bien pero con gusto puedes checarlo en GitHub, ahi esta el producto completo se llama “CovidGto”