2017-12-29 21 views
0

"struct course"변수에 액세스하여 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 
    } 

하지만 난 커버 변수에 액세스 및 예제 소스 값을 얻고있는 tableView에 추가 할 수있는 방법을 알아낼 질수 :있는 tableView에

var event = [Course]() 
//some code left out 
let courses = try JSONDecoder().decode(JsonFromWeb.self, from: data) 
self.event = courses.data 
//some code left out 

그리고 다음을 :이처럼 않습니다. Course 변수와 마찬가지로. 내 구조체가 여기에 있습니다 : (내 JSON을 사용하여이 코딩 사용자 Vadian 학점.)

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 
} 

희망 도움을 찾을 수 있습니다. 고맙습니다!

답변

1

그것은 간단합니다 :

cover 사용 source에 액세스하려면

event[indexPath.row].cover?.source 
관련 문제