Swift) Decodable, custom Decoder 복잡한 데이터 모델을 나누는 방법에 대해서
·
앱/Swift
DecodableDecoder는 JSON type으로 오는 데이터를 네이티브한 포멧과 매핑이 가능하도록 하는 프로토콜이다.보통 Codable이 Encodable, Decodable 두개를 타입엘리어싱 하기 때문에 Codable만 채택해도 큰 문제는 없다.CodingKey실제로 RESTFUL API와 실제로 내부에서 사용하는 데이터의 네이밍이 다른경우가 많은데 이를 코딩키를 통해서 매핑해줄수 있다.struct DecodingModel: Decoding { let userName: String let userAge: Int enum CodingKeys: String, CodingKey { case userName = "user_name" case userAge = "user_age" ..