SwiftData model inheritance
Shows when and how to subclass SwiftData models, query by type and migrate, so your iOS 26 data model stays clean.
What we improved
Added a "Requirements First" section: model inheritance arrived with the OS 26 releases, and subclasses (plus schemas and migration stages that name them) need `@available(iOS 26, *)` when the deployment target is lower. The original never
Improved by YourAISkill from the original by rshankras, under its MIT licence. The download includes the author's licence and a CHANGES.md listing every change. Both Claude reviews read the improved version.
Claude's review
8/10 Grounded SwiftData inheritance guide with a decision tree, deep and shallow predicates, availability and migration steps, and hedged known pitfalls.
We asked Claude the question you would ask: would I be glad I installed this? Two separate reviews, the second blind to the first, must both rate a skill 7 or higher before we sell it.
In detail
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.
How you use it
- Add it to your pack, then download your pack (1 credit).
- In Claude, open Customize > Skills and upload the zip. Code execution needs to be on under Settings > Capabilities.
- Ask Claude for the job in your own words. It uses the skill when your request matches what it does. Step by step guide
Safety check
Nothing risky found: no hidden instructions, no download and run, no reading of saved passwords or keys.
An automated scan lowers risk but cannot promise zero risk. How we check skills
Preview
The first lines of SKILL.md
---
name: swiftdata-inheritance
description: "SwiftData class inheritance (new in the OS 26 releases, such as iOS 26): when to subclass a @Model instead of using an enum or protocol, how to declare, annotate and register subclasses, deep and shallow queries with #Predicate type checks, polymorphic relationships, and the schema migration that introduces subclasses. Use when designing or reviewing a SwiftData model hierarchy, filtering a list by subclass, or moving a Core Data entity inheritance hierarchy to SwiftData."
allowed-tools: [Read, Glob, Grep]
last_verified: 2026-12-02
review_by: 2027-06-22
---
<!-- Modified by YourAISkill (youraiskill.com) on 2 December 2026 from the original by rshankras. See CHANGES.md. -->
# SwiftData Class Inheritance
Guide for implementing class inheritance in SwiftData models. Covers when to use inheritance versus enums or protocols, how to annotate and register subclasses, how to query across a hierarchy, and the pitfalls in relationships and schema migration.
The patterns follow Apple's WWDC25 session "SwiftData: Dive into inheritance and schema migration" (session 291), which uses the same `Trip`, `BusinessTrip` and `PersonalTrip` example.
## When This Skill Activates
- User is designing a SwiftData model hierarchy with shared base properties
- User asks about `@Model` on subclasses or how inheritance works in SwiftData
- User needs to query across a type hierarchy (all trips vs only business trips)
- User is deciding between inheritance, enums, or protocols for model variants
- User has issues with polymorphic relationships or type casting in SwiftData
- User is migrating a Core Data inheritance hierarchy to SwiftData
## Requirements First
- **OS version.** SwiftData model inheritance arrived with the OS 26 releases (iOS 26 and its sibling releases) and needs the matching SDK (Xcode 26). Check Apple's SwiftData documentation for the exact platform list your app targets.
- **Lower deployment target.** If the app still supports older systems, mark every subclass, and everything that names a subclass, with availability, as Apple's sample does: `@available(iOS 26, *)` (add `macOS 26` and so on for multiplatform targets). That includes the `VersionedSchema` that lists the subclasses and the migration stage that reaches it. On older systems the app keeps using the base model only.
- **Check before advising.** Before recommending inheritance, read the project's deployment target. If it is below 26 and the user cannot raise it, an enum property on the base model is usually the better answer.
## Decision Tree
```
Do your model variants share a common identity and most properties?
|
+-- YES: Clear IS-A relationship (BusinessTrip IS-A Trip)
| |
| +-- Do you fetch BOTH "all trips" (deep) AND "only business trips" (shallow)?
| | +-- YES --> Use class inheritance (this skill)
| | +-- Only ever "all trips" --> Make the kind an enum property on Trip
...From rshankras's repository, MIT licence.
Related skills
-
Checked
iPhone interface guidelines
Applies Apple's iPhone design guidelines in SwiftUI and UIKit, so your app feels at home on iOS.
7/101 credit -
Checked
App Store rejection check
Reviews Apple app code against the App Store Review Guidelines to catch rejection risks before you submit.
7/101 credit -
Checked
SwiftUI iOS 17 modernisation
Scans your Swift code for old patterns and plans the move to iOS 17 APIs, so you migrate without breaking the app.
8/101 credit -
Checked
Liquid Glass for iOS apps
Shows where Apple's Liquid Glass belongs in your iOS app and how to build it, so screens stay clear and readable.
8/101 credit -
Checked
3D charts in SwiftUI
Builds 3D surface and scatter charts in SwiftUI for iOS 26 with a 2D fallback, so people can rotate your data.
8/101 credit -
Checked
Capacitor iOS hardening
Tightens Xcode security settings and native plugin code in a Capacitor iOS app, one safe step at a time.
7/101 credit