대부분 코드와 관련된 내용이기 때문에, Github에 업로드해두었다.

스크린샷 2023-08-03 오후 6.24.32.png

CodingKey

만약 api 응답 데이터가 Swift Naming 규칙에 어긋날 때에는 CodingKey protocol을 이용해 Swift Naming 규칙에 맞게 변환할 수 있다.

/// - IMPORTANT: api 응답 데이터가 Snake_case 등 Swift Naming 규칙에 어긋나는 경우.
/// CodingKey를 사용한다.

struct Track2: Codable {
    let title: String
    let artistName: String
    let isStreamable: Bool
    
    enum CodingKeys: String, CodingKey {
        case title = "track_name"
        case artistName = "artist_name"
        case isStreamable = "is_streamable"
    }
}

참고자료