swiftdata-inheritance

Implement SwiftData class inheritance with @Model annotations and type-based queries.

Updated Mar 1, 2026
One-click install
npx skills add https://github.com/mazicimert/RunDom --skill swiftdata-inheritance-mazicimert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata-inheritance
Source: https://github.com/mazicimert/RunDom/tree/main/.claude/skills/swiftdata/inheritance
Command: npx skills add https://github.com/mazicimert/RunDom --skill swiftdata-inheritance-mazicimert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SwiftData class inheritance patterns for hierarchical models with type-based querying, polymorphic relationships, and when to choose inheritance vs enums. Use when designing SwiftData model hierarchies.

Core Features & Use Cases

  • Guidance on when to use inheritance vs enums or protocols for SwiftData models.
  • Query across type hierarchies enabling deep and shallow fetches for all or specific subtypes.
  • Migration and relationship modeling tips to avoid common pitfalls during schema evolution.

Quick Start

Start by modeling a base class with @Model, then create one or more subclasses with @Model and ensure super.init() is invoked in initializers, while keeping the hierarchy shallow to minimize migration risk.

Frequently Asked Questions about swiftdata-inheritance

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

FAQPage Schema
How do I implement SwiftData class inheritance for hierarchical data models?

SwiftData class inheritance requires annotating both your base class and subclasses with @Model, ensuring proper super.init() calls in subclass initializers to enable polymorphic relationships and type-based querying across shared base properties.

When should I use SwiftData inheritance versus enums or protocols?

SwiftData inheritance suits hierarchical models needing shared base properties and type-based queries. Choose enums or protocols when your data represents distinct variants without shared state, or when you want to minimize migration risk during schema evolution by keeping model hierarchies shallow.

Can I perform type-based queries across SwiftData subclass hierarchies?

Type-based queries in SwiftData allow deep and shallow fetches across subclass hierarchies. You can fetch all subtypes using the base class or target specific subtypes, enabling polymorphic data retrieval across your inherited model structures.

What are the migration risks with SwiftData model inheritance?

SwiftData model inheritance migration risks increase with deeper hierarchies. Keep hierarchies shallow to minimize schema evolution pitfalls, and carefully plan migration strategies when modifying base or subclass properties to ensure polymorphic relationships remain intact.

Does SwiftData inheritance support polymorphic relationships?

Polymorphic relationships in SwiftData inheritance connect different subtypes through shared base classes. By annotating base and subclasses with @Model, you can model relationships that reference any subtype instance while maintaining type-based query capabilities.