Agent skill · software engineering · dpearson2699
swift-codable
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.
Why this skill is useful
Provides specific patterns and strategies for implementing Swift Codable models that the AI wouldn't reliably generate on its own.
What it needs
About 6k tokens when loaded. Last updated 2026-07-31. 973 stars on the source repository.
What this skill does
Swift Codable Encode and decode Swift types using Codable (Encodable & Decodable) with JSONEncoder, JSONDecoder, and related APIs. Targets Swift 6.3 / iOS 26+. Contents Decode and Verify Workflow Basic Conformance Custom CodingKeys Custom Decoding and Encoding Nested and Flattened Containers Heterogeneous Arrays Date Decoding Strategies Data and Key Strategies Lossy Array Decoding Single Value Containers Default Values for Missing Keys Encoder and Decoder Configuration Codable with URLSession Codable with SwiftData Codable with UserDefaults Common Mistakes Review Checklist References Decode and Verify Workflow 1. Decode representative success, missing, null, malformed, acronym-key, and date fixtures. 2. On failure, inspect DecodingError, its codingPath, and the raw payload. 3. Correct only the mismatched model, key, container, or strategy; do not hide contract failures with lossy decoding. 4. Rerun fixtures and encode/decode round trips where both directions are part of the contract. Basic Conformance When all stored properties are themselves Codable, the compiler synthesizes conformance automatically: Prefer Decodable for read-only API responses and Encodable for write-only. Use Codable only when both directions are required. Custom CodingKeys Rename JSON keys without writing a custom decoder by declaring a CodingKeys enum: Every stored property must appear in the enum. Omitting a property from CodingKeys excludes it from encoding/decoding -- provide a default value or compute it separately. Custom Decoding and Encoding Override init(from:) and encode(to:) for transformations the synthesized conformance cannot handle: Nested and Flattened Containers Use nestedContainer(keyedBy:forKey:) to navigate and flatten nested JSON: Chain multiple nestedContainer calls to flatten deeply nested structures. Also use nestedUnkeyedContainer(forKey:) for nested arrays. Heterogeneous Arrays Load Advanced Codable Patterns for discriminator-based mixed arrays. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills dpearson2699/swift-codable