Codable: Encoding and Decoding JSON
Conforming to Codable, custom CodingKeys and nested container decoding.
Codable Protocol
Codable is a type alias for Encodable & Decodable. Conforming types can be encoded to and decoded from JSON automatically.
struct User: Codable {
var name: String
var age: Int
}Automatic Synthesis
Swift synthesizes Codable implementations when all stored properties are themselves Codable.
struct Product: Codable {
var id: Int
var title: String
var price: Double
// init(from:) and encode(to:) are auto-generated
}All lessons in this course
- URLSession data(from:) with async/await
- Codable: Encoding and Decoding JSON
- Error Handling and HTTP Status Codes
- Retry Logic and Background URLSession