cellForRow
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
-> UITableViewCell {
guard let cell =
tableView.dequeueReusableCell(withIdentifier: "EventsCell") as? EventsCell
else { return UITableViewCell() }
cell.homeLabel.text = events[indexPath.row].homeTeamName
cell.awayLabel.text = events[indexPath.row].awayTeamName
cell.homeGoalLbl.text =
String (describing: events[indexPath.row].result.goalsHomeTeam)
cell.awayGoalLbl.text =
String (describing: events[indexPath.row].result.goalsAwayTeam)
return cell
}
Codables
class EventsFull: Codable {
let fixtures: [EventsData]
init(fixtures: [EventsData]) {
self.fixtures = fixtures
}
}
class ResultsData: Codable {
let goalsHomeTeam: Int?
let goalsAwayTeam: Int?
init(goalsHomeTeam: Int,goalsAwayTeam: Int) {
self.goalsHomeTeam = goalsHomeTeam
self.goalsAwayTeam = goalsAwayTeam
}
}
class EventsData: Codable {
let date: String
let status: String
let matchday: Int
let homeTeamName: String
let awayTeamName: String
let result: ResultsData
let odds: Double?
init(date: String, status: String, matchday: Int, homeTeamName: String, awayTeamName: String, result: ResultsData, odds: Double) {
self.date = date
self.status = status
self.matchday = matchday
self.homeTeamName = homeTeamName
self.awayTeamName = awayTeamName
self.result = result
self.odds = odds
}
}
Консоль
downloaded
Optional(3)
Optional(2)
Как убрать Optional из вида и как "ноль" не появляется?