일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Tuist
- Subscribe
- ios database
- swift 6
- swift 5.9
- ribs
- SwiftUI
- realm
- RxSwift
- ios
- swiftdata
- 네트워크 통신
- arc
- swift db
- Firebase
- swift
- observable
- 카카오뱅크 ios
- GCD
- Tuist Swift
- KeyPath
- Subject
- swift database
- Swift Tuist
- Combine
- ios swiftdata
- xcode
- JSON
- Firebase Analytics
- SeSAC
- Today
- Total
목록JSON (2)
천원의 개발

Codable - JSON과 같은 외부 표현과의 호환성을 위해 데이터 유형을 인코딩 및 디코딩할 수 있는 프로토콜입니다. - Codable = Decodable & Encodable Codable은 Decodable과 Encodable을 준수하는 프로토콜인데 그러면 Decodable과 Encodable을 알아 보겠습니다. Decodable - 원하는 모델로 데이터를 디코딩 할 수 있는 프로토콜입니다. - Key의 일부를 디코딩 하지 않는 것은 문제가 없습니다. - 보통 Struct에 채택하여 사용하며, Enum과 Class 또한 채택할 수 있습니다. 아래와 같은 형태의 JSON 데이터가 있다면 { "blogName": "천원의 개발", "userID": "1000원", "number" : 111 } 아래..

먼저 받아 오려는 JSON데이터 부터 확인후 그에 맞게 구조체를 만들어준다! 여기서 temp를 받아오고 싶다면! 요로코롬 구조체 만들어 주고 struct Data: Decodable{ let main: Main } struct Main: Decodable{ let temp: Double } 그 후에 let decoder = JSONDecoder() do{ let decodedData = try decoder.decode(Data.self, from: data) // data에 URLSession으로 받아온 data 넣어준다! print(decodedData.main.temp) // 출력! } catch{ print(error) }