일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- url
- instance
- enum
- tuist
- extension
- Unicode
- 이니셜라이저
- Xcode
- 스위프트
- Terminal
- IOS
- optional
- Class
- String
- UIKit
- Swift
- struct
- initializer
- delegate
- interpace
- Protocol
- init
- 코딩테스트
- type
- property
- Method
- 디자인패턴
- Foundation
- initalizer
- Git
Archives
- Today
- Total
목록Encodable (1)
아리의 iOS 탐구생활
[Swift/iOS] Codable로 JSON을 파싱해보자.
🔍 Codable이 뭘까? Codable은 Decodable와 Encodable를 준수하는 타입(프로토콜)이다. JSON 데이터를 간편하고 쉽게 인코딩 & 디코딩 할 수 있게 해준다. typealias Codable = Decodable & Encodable 구조체, 클래스, 열거형 모두 Codable을 채택할 수 있다. 먼저 JSON을 인코딩 및 디코딩을 하는데 이용할 타입을 만들어주고 Codable를 채택하자. struct Person: Codable { // Codable 프로토콜 채택 var name: String var age: Int } 👉🏻 JSON 만들기 (Encoding) JSONEncoder를 선언한다. JSONEncoder의 encode메소드를 사용하여 인스턴스를 Data타입으로 만든..
Swift/iOS
2021. 8. 22. 16:55