func configureStackView(koreaCovidOverview: CovidOverview) {
self.totalCaseLabel.text = "\\(koreaCovidOverview.totalCase) 명"
self.newCaseLabel.text = "\\(koreaCovidOverview.newCase) 명"
}
override func viewDidLoad() {
- 생략 -
switch result {
case let .success(result):
//configureStackView의 파라미터에 확진자수데이터를 넘겨 라벨에표시
👉self.configureStackView(koreaCovidOverview: result.korea)
case let .failure(error):
debugPrint("failure \\(error)")
}
})
}
Alamofire의 responseDate 컴플리션핸들러는 메인스레드에서 작동하기때문에 DispatchQueue키워드를 사용하지 않아도 된다.
▼결과

func makeCovidOverviewList(cityCovidOverview: CityCovidOverview) -> [CovidOverview] {
return [ // ㄴ CovidOverview배열로 반환
//JSON응답은 배열이아닌 하나의 객체로 오기때문에 CityCovidOverview객체안에있는 시도별 객체를 배열에 추가한다.
cityCovidOverview.seoul,
cityCovidOverview.busan,
cityCovidOverview.daegu,
cityCovidOverview.incheon,
cityCovidOverview.gwangju,
cityCovidOverview.daejeon,
cityCovidOverview.ulsan,
cityCovidOverview.sejong,
cityCovidOverview.gyeonggi,
cityCovidOverview.chungbuk,
cityCovidOverview.chungnam,
cityCovidOverview.jeonnam,
cityCovidOverview.gyeongbuk,
cityCovidOverview.gyeongnam,
cityCovidOverview.jeju,
]
}