swiftdata-inheritance

Design class-based SwiftData model hierarchies with polymorphic relationships and type-filtered queries.

4|1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill swiftdata-inheritance-autisticaf
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftdata-inheritance
Source: https://github.com/AutisticAF/claude-code-apple-dev-plugin/tree/main/skills/swiftdata-inheritance
Command: npx skills add https://github.com/AutisticAF/claude-code-apple-dev-plugin --skill swiftdata-inheritance-autisticaf

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps Swift developers design and implement class-based SwiftData model hierarchies so shared identity, polymorphism, and type-based querying work correctly while avoiding migration and relationship pitfalls.

Core Features & Use Cases

  • Decision guidance for when to use class inheritance versus enums or protocols for model variants.
  • Modeling patterns including base and subclass @Model usage, relationship placement, and ModelContainer registration.
  • Querying techniques for deep (base-class) and type-filtered predicates and runtime casting in views.
  • Migration and review checklist to avoid common mistakes such as missing @Model annotations, forgetting super.init(), or over-deep hierarchies.

Quick Start

Ask the assistant to design a Trip/BusinessTrip SwiftData inheritance model, produce annotated @Model class definitions, sample deep and filtered queries, and practical migration notes.

Frequently Asked Questions about swiftdata-inheritance

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

FAQPage Schema
How do I set up SwiftData model inheritance for polymorphic relationships?

SwiftData model inheritance requires applying @Model to both base and subclasses, placing relationships correctly, and registering all types in ModelContainer to support polymorphic relationships and querying across subclasses.

When should I use class inheritance versus enums or protocols for SwiftData model variants?

Class inheritance suits SwiftData model variants when you need shared identity and type-filtered querying, whereas enums or protocols fit lightweight state differences without persisting shared hierarchical data.

How do I query SwiftData subclasses using type-filtered predicates?

Querying SwiftData subclasses uses type-filtered predicates to fetch specific subtypes from base-class lists, combined with runtime casting in views to display polymorphic results correctly.

What are common migration pitfalls when designing SwiftData model hierarchies?

Common SwiftData migration pitfalls include missing @Model annotations on subclasses, forgetting super.init(), over-deep hierarchies, and incorrect relationship placement, all addressed by a migration review checklist.

Can I migrate Core Data models to SwiftData class hierarchies?

Migrating Core Data models to SwiftData class hierarchies requires applying @Model to base and subclasses, updating ModelContainer registration, and verifying type-filtered predicates and relationships work post-migration.

Why does my SwiftData subclass query return base class instances instead of subtypes?

SwiftData subclass queries return base class instances when @Model annotations are missing or ModelContainer lacks subclass registration, preventing type-filtered predicates from fetching polymorphic subtypes correctly.