처음에 API 응답을 받을 때 rates가 [String: Double] 형태의 딕셔너리여서
기존에 사용하던 배열 기반 모델(struct Currency { let name: String; let rate: Double })로는 직접 파싱할 수 없었음
Codable은 보통 [Currency]처럼 배열을 파싱할 때 많이 써서
딕셔너리를 어떻게 파싱할지 감이 안 왔음..
실제 API 응답 형태를 다시 확인해서 rates가 딕셔너리라는 걸 인지
ExchangeRateResponse 모델에서 rates: [String: Double]로 선언하여 해결
ViewModel에서 dict.map { ($0.key, $0.value) }로 튜플 배열로 변환해서 정렬하고 테이블뷰에 활용
네트워크 요청이 실패할 때 Alert를 띄우려고 했지만 아무 반응이 없었음
present(alert, animated: true)를 호출했는데도 경고창이 안 뜸
ViewModel에서 background thread (URLSession.dataTask) 내에서 Alert를 띄우려고 해서 발생한 거 같았음
UIKit은 반드시 main thread에서만 UI를 조작해야 함
DispatchQueue.main.async {
self?.onError?("데이터를 불러올 수 없습니다")
}
→ main thread로 올려서 UI 처리하게 함
셀을 등록했는데도 앱이 크래시 발생 : Unable to dequeue cell...
ExchangeRateCell.identifier를 잘못 입력하거나 register를 잊은 듯 했음
tableView.register(ExchangeRateCell.self, forCellReuseIdentifier: ExchangeRateCell.identifier)
→ 셀 클래스와 identifier를 정확히 등록하고 해결