swift-codable

Convert JSON and property-list responses into Swift Codable models.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/DFly7/iOS-FastAPI-Supabase-AI --skill swift-codable
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-codable
Source: https://github.com/DFly7/iOS-FastAPI-Supabase-AI/tree/main/.agents/skills/swift-codable
Command: npx skills add https://github.com/DFly7/iOS-FastAPI-Supabase-AI --skill swift-codable

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Simplifies converting unstructured API payloads into strongly typed Swift data models and reduces runtime decoding errors by providing idiomatic Codable patterns and encoder/decoder configurations.

Core Features & Use Cases

  • Automatic and manual conformance: When all properties are Codable the compiler synthesizes conformance, and the guide shows when to use Decodable or Encodable separately.
  • Key remapping and nested flattening: Use CodingKeys and nested containers to rename JSON keys and flatten nested objects into model properties.
  • Custom encoding/decoding: Implement init(from:) and encode(to:) for timestamp conversions, default values, and validation.
  • Date, data, and key strategies: Configure JSONDecoder and JSONEncoder for ISO8601, timestamps, base64 data, and snake_case conversion.
  • Robust array handling: Patterns for decoding heterogeneous arrays and lossy array decoding to skip invalid elements.
  • Platform integration: Examples for use with URLSession responses, SwiftData composite attributes, PropertyListEncoder/Decoder, and AppStorage via RawRepresentable.
  • Best practices and checklist: Common mistakes, deterministic encoder settings for tests, and a review checklist for production-ready models.

Quick Start

Create Swift Codable structs for the provided JSON, mapping snake_case keys to camelCase, decoding ISO8601 dates, and skipping malformed elements in arrays.

Frequently Asked Questions about swift-codable

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decode JSON with snake_case keys into Swift Codable models using camelCase?

To decode JSON with snake_case keys into Swift Codable models, define custom CodingKeys to remap keys, or configure JSONDecoder with a convertFromSnakeCase key decoding strategy for automatic camelCase conversion.

What is the best way to parse ISO8601 dates and timestamps in Swift JSONDecoder?

The best way to parse ISO8601 dates and timestamps in Swift JSONDecoder is setting the dateDecodingStrategy to .iso8601, or implementing a custom init(from:) decoder for heterogeneous timestamp formats.

How to handle lossy arrays and skip invalid elements during Swift Codable decoding?

To handle lossy arrays and skip invalid elements during Swift Codable decoding, implement a custom init(from:) using a UnkeyedContainer to catch decoding errors per element, preventing the entire array parse from failing.

Can I flatten nested JSON objects into single Swift Codable structs?

Yes, you can flatten nested JSON objects into single Swift Codable structs by defining nested containers within a custom init(from:) implementation to extract and map nested values directly to top-level properties.

Does Swift Codable work with URLSession, SwiftData, and AppStorage?

Swift Codable works with URLSession, SwiftData, and AppStorage. You can decode URLSession API responses, use Codable structs as SwiftData composite attributes, and conform types to RawRepresentable for AppStorage persistence.

Why does JSONDecoder fail when decoding base64 data in Swift?

JSONDecoder fails when decoding base64 data in Swift if the payload contains invalid characters or incorrect padding. Use a custom init(from:) to decode the base64 string manually via Data(base64Encoded:) for safer error handling.