All skills
Skillintermediate
/add-model - Add Data Model
Create a Swift data model with Codable conformance and validation.
Claude Code Knowledge Pack7/10/2026
Overview
/add-model - Add Data Model
Create a Swift data model with Codable conformance and validation.
Steps
- Ask the user for the model name and its properties with types
- Create the model struct with Codable conformance
- Add proper property types: String, Int, Double, Date, URL, optional types
- Implement CodingKeys enum for JSON key mapping if API uses different naming
- Add custom Decodable init for complex parsing (nested objects, date formats)
- Implement Equatable and Hashable conformance for use in collections and SwiftUI
- Add Identifiable conformance with a unique ID property
- Create validation methods for business rules (email format, required fields)
- Add computed properties for derived values (full name, formatted date)
- Create a mock/preview instance for SwiftUI previews and testing
- Add the model to the appropriate module or feature directory
- Create unit tests for encoding, decoding, and validation
Rules
- Use structs for models, not classes, unless reference semantics are required
- Make properties immutable (let) unless mutation is explicitly needed
- Handle optional fields gracefully with nil-coalescing or default values
- Use ISO 8601 date format for JSON dates with a custom decoder
- Include a static preview instance for SwiftUI development
- Follow Swift naming conventions: camelCase properties, PascalCase types
- Do not expose internal implementation details in the model's public API