Ich weiß, wie man auf "struct Course" Variablen zugreifen und sie zur Tabellenansicht bringen. Ich mache es wie folgt aus:Wie liest man eine Variable aus der Struktur der dritten Ebene?
var event = [Course]()
//some code left out
let courses = try JSONDecoder().decode(JsonFromWeb.self, from: data)
self.event = courses.data
//some code left out
Und dann in Tableview:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "eventCell") as? UserEventsTableViewCell else { return UITableViewCell() }
cell.idLabel.text = event[indexPath.row].id
cell.nameLabel.text = event[indexPath.row].name
return cell
}
Aber ich kann nicht die Art und Weise herauszufinden, Titel Variablen zugreifen und zum Beispiel Quellenwert erhalten und fügen Sie ihn in Tableview. Wie ich es mit Kursvariablen getan habe. Meine Struktur ist hier ein: (Kredite an Benutzer Vadian, die diese codiert meine JSON verwenden.)
struct JsonFromWeb: Codable {
let data: [Course]
}
struct Course: Codable {
private enum CodingKeys : String, CodingKey {
case attendingCount = "attending_count"
case id, name, cover
}
let id: String
let name: String
let attendingCount: Int
let cover: Cover?
}
struct Cover : Codable {
private enum CodingKeys : String, CodingKey {
case offsetX = "offset_x"
case offsetY = "offset_y"
case source, id
}
let offsetX: Int
let offsetY: Int
let source: String
let id: String
}
Hoffnung, Hilfe zu finden. Vielen Dank!