← ClaudeAtlas

swift-codablelisted

Implement Swift Codable models for JSON and property-list encoding and decoding with JSONDecoder, JSONEncoder, CodingKeys, and custom init(from:) or encode(to:). Use when parsing API responses, remapping keys, flattening nested JSON, handling date or data decoding strategies, decoding heterogeneous arrays, or integrating Codable with URLSession, SwiftData, or UserDefaults.
dpearson2699/swift-ios-skills · ★ 730 · AI & Automation · score 80
Install: claude install-skill dpearson2699/swift-ios-skills
# Swift Codable Encode and decode Swift types using `Codable` (`Encodable & Decodable`) with `JSONEncoder`, `JSONDecoder`, and related APIs. Targets Swift 6.3 / iOS 26+. ## Contents - [Basic Conformance](#basic-conformance) - [Custom CodingKeys](#custom-codingkeys) - [Custom Decoding and Encoding](#custom-decoding-and-encoding) - [Nested and Flattened Containers](#nested-and-flattened-containers) - [Heterogeneous Arrays](#heterogeneous-arrays) - [Date Decoding Strategies](#date-decoding-strategies) - [Data and Key Strategies](#data-and-key-strategies) - [Lossy Array Decoding](#lossy-array-decoding) - [Single Value Containers](#single-value-containers) - [Default Values for Missing Keys](#default-values-for-missing-keys) - [Encoder and Decoder Configuration](#encoder-and-decoder-configuration) - [Codable with URLSession](#codable-with-urlsession) - [Codable with SwiftData](#codable-with-swiftdata) - [Codable with UserDefaults](#codable-with-userdefaults) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## Basic Conformance When all stored properties are themselves `Codable`, the compiler synthesizes conformance automatically: ```swift struct User: Codable { let id: Int let name: String let email: String let isVerified: Bool } let user = try JSONDecoder().decode(User.self, from: jsonData) let encoded = try JSONEncoder().encode(user) ``` Prefer `Decodable` for read-only API responses and `Encodable`