swift-codable

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

Updated May 10, 2026
One-click install
npx skills add https://github.com/FelixRauch/medat-figuren --skill swift-codable-felixrauch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-codable
Source: https://github.com/FelixRauch/medat-figuren/tree/main/.agents/skills/swift-codable
Command: npx skills add https://github.com/FelixRauch/medat-figuren --skill swift-codable-felixrauch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the problem of turning JSON or property-list data into usable Swift models (and back again) without fragile, manual parsing.

Core Features & Use Cases

  • Custom CodingKeys to map mismatched field names (e.g., snake_case to Swift properties).
  • Custom init(from:) and encode(to:) to transform values (like Unix timestamps) when synthesized Codable isn’t enough.
  • Robust decoding patterns for nested structures, heterogeneous arrays, lossy arrays, and correct date/data/key decoding strategies.
  • Practical integrations with URLSession, SwiftData composite attributes, and UserDefaults storage via RawRepresentable.

Quick Start

Configure a JSONDecoder (including dateDecodingStrategy and keyDecodingStrategy) and decode your API payload into your Codable models, using CodingKeys or init(from:) to handle key remapping and type conversions as needed.

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 mismatched field names in Swift?

To decode JSON with mismatched field names in Swift, implement custom CodingKeys within your Codable structs to map snake_case or varying API keys directly to your Swift property names. This ensures correct parsing without manual transformation logic.

What is the best way to parse nested JSON structures and heterogeneous arrays in Swift?

The best way to parse nested JSON structures and heterogeneous arrays in Swift is by applying robust decoding patterns with custom init(from:) initializers. This handles complex data shapes and lossy arrays safely when synthesized Codable logic is insufficient.

How do I handle Unix timestamps and custom dates during JSON encoding in Swift?

To handle Unix timestamps and custom dates during JSON encoding in Swift, configure JSONEncoder dateEncodingStrategy and use custom encode(to:) methods. This transforms specific date formats accurately for API integration and data flow.

Can I use Swift Codable with URLSession and SwiftData composite attributes?

Yes, you can use Swift Codable with URLSession and SwiftData composite attributes. Codable models integrate directly with URLSession API payloads and support SwiftData composite attribute storage for resilient application data flow.

Why does my JSON decoding fail when parsing lossy arrays in Swift?

JSON decoding fails when parsing lossy arrays in Swift because standard synthesized Codable expects strict type homogeneity. Implement custom decoding containers within init(from:) to skip invalid elements and prevent the entire parsing operation from failing.