swift-codable

Define Swift Codable models to encode and decode JSON and plist data.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/onymchat/onym-ios --skill swift-codable-onymchat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-codable
Source: https://github.com/onymchat/onym-ios/tree/main/.claude/skills/swift-codable
Command: npx skills add https://github.com/onymchat/onym-ios --skill swift-codable-onymchat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Implement Swift Codable models for JSON and property-list encoding/decoding, including handling CodingKeys, nested containers, and custom init(from:) or encode(to:) overrides.

Core Features & Use Cases

  • Automatic synthesis of Codable conformance for simple models and custom coding strategies for complex mappings.
  • Support for date and data decoding strategies, nested structures, and persistence scenarios (URLSession, SwiftData, UserDefaults).
  • Real-world example: model a REST API response with nested dictionaries and date fields, then encode to JSON for network requests or save to UserDefaults.

Quick Start

Create a Codable struct for a sample API response and decode the JSON into that struct using JSONDecoder.

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 nested dictionaries and custom date formats in Swift?

To decode JSON with nested dictionaries and custom date formats in Swift, define a Codable struct using CodingKeys and nested containers, then apply a custom date decoding strategy via JSONDecoder to map the API response accurately.

What's the best way to remap JSON keys to different Swift property names?

The best way to remap JSON keys to different Swift property names is to define custom CodingKeys within your Codable struct, enumerating the exact string keys from the JSON payload to map them to your local Swift variables.

Do I need to manually implement init(from:) for every Swift Codable model?

You do not need to manually implement init(from:) for every Swift Codable model, because the compiler automatically synthesizes Codable conformance for simple models, requiring manual overrides only for complex mappings or nested containers.

Can I use Swift Codable to save and retrieve data from UserDefaults or SwiftData?

You can use Swift Codable to save and retrieve data from UserDefaults or SwiftData by encoding your models into JSON or plist data with JSONEncoder, then persisting the encoded data locally for later decoding.

How does Swift Codable handle plist encoding compared to JSON?

Swift Codable handles plist encoding similarly to JSON by using PropertyListEncoder and PropertyListDecoder, allowing the same Codable structs to serialize data into property lists with support for custom date and data strategies.