app-store
App Store optimization and marketing skills for descriptions, screenshots, keywords, review responses, and comprehensive…
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.
Claude Code
$ npx -y skills add rshankras/claude-code-apple-skills --skill inheritance --agent claude-code
Codex
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a codex -y
Cursor
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a cursor -y
Gemini CLI
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a gemini-cli -y
GitHub Copilot
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a github-copilot -y
OpenCode
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a opencode -y
Windsurf
$ npx skills add rshankras/claude-code-apple-skills --skill inheritance -a windsurf -y
name: swiftdata-inheritance description: 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. allowed-tools: [Read, Glob, Grep] last_verified: 2026-07-16 review_by: 2027-06-22
Guide for implementing class inheritance in SwiftData models. Covers when to use inheritance versus enums or protocols, how to annotate subclasses, query across hierarchies, and avoid common pitfalls with schema migrations and relationship modeling.
Do your model variants share a common identity and most properties?
|
+-- YES: Clear IS-A relationship (BusinessTrip IS-A Trip)
| |
| +-- Subclasses add significant unique properties or behavior?
| | +-- YES --> Use class inheritance (this skill)
| | +-- NO, just 1-2 distinguishing fields --> Use enum property on base model
| |
| +-- Need to query "all trips" AND "only business trips"?
| +-- YES --> Inheritance gives you both for free
| +-- Only one type at a time --> Enum filter is simpler
|
+-- NO: Models share only a few properties
| +-- Use protocol conformance (no SwiftData inheritance needed)
|
+-- UNCERTAIN: Could go either way
+-- Prefer enum on base model (simpler schema, easier migrations)
+-- Promote to inheritance later if variants diverge significantlyApply `@Model` to the base class. All persistent properties live here.
@Model
class Trip {
var name: String
var startDate: Date
var endDate: Date
@Attribute(.preserveValueOnDeletion)
var identifier: UUID
@Relationship(deleteRule: .cascade, inverse: \Accommodation.trip)
var accommodations: [Accommodation] = []
init(name: String, startDate: Date, endDate: Date) {
self.identifier = UUID()
self.name = name
self.startDate = startDate
self.endDate = endDate
}
}Apply `@Model` to each subclass. Call `super.init()` and add subclass-specific stored properties.
@Model
class BusinessTrip: Trip {
var company: String
var expenseReport: String?
var meetingAgenda: String?
init(name: String, startDate: Date, endDate: Date, company: String) {
self.company = company
super.init(name: name, startDate: startDate, endDate: endDate)
}
}
@Model
class PersonalTrip: Trip {
enum Reason: String, Codable {
case vacation
case family
case adventure
}
var reason: Reason
var companions: [String] = []
init(name: String, startDate: Date, endDate: Date, reason: Reason) {
self.reason = reason
super.init(name: name, startDate: startDate, endDate: endDate)
}
}Relationships defined on the base class apply to all subclasses:
@Model
class Accommodation {
var name: String
// Points to Trip -- could be BusinessTrip or PersonalTrip at runtime
@Relationship(inverse: \Trip.accommodations)
var trip: Trip?
init(name: String) { self.name = name }
}Register the base class. SwiftData discovers subclasses automatically.
// Register Trip -- BusinessTrip and PersonalTrip are included automatically let container = try ModelContainer(for: Trip.self, Accommodation.self, Itinerary.self)
Querying the base class returns instances of every subclass.
// Returns Trip, BusinessTrip, and PersonalTrip instances @Query(sort: \Trip.startDate) var allTrips: [Trip]
Narrow results to a specific subclass using `is` or `as?` in a `#Predicate`.
// Only BusinessTrip instances
let businessOnly = #Predicate<Trip> { trip in
trip is BusinessTrip
}
@Query(filter: #Predicate<Trip> { $0 is BusinessTrip }, sort: \Trip.startDate)
var businessTrips: [Trip]Access subclass-specific properties with conditional casting inside the predicate.
let vacationTrips = #Predicate<Trip> { trip in
if let personal = trip as? PersonalTrip {
personal.reason == .vacation
} else {
false
}
}A common pattern for filter controls that switch between all trips and a specific type.
enum TripFilter: String, CaseIterable, Identifiable {
case all, business, personal
var id: String { rawValue }
}
struct TripListView: View {
@State private var filter: TripFilter = .all
@Query(sort: \Trip.startDate) var allTrips: [Trip]
var filteredTrips: [Trip] {
switch filter {
cA collection of Claude Code skills for iOS, macOS, watchOS, visionOS, and Apple platform development. These skills help you plan and build apps, maintain code quality, ensure HIG compliance, and guide you from idea to App Store.
App Store optimization and marketing skills for descriptions, screenshots, keywords, review responses, and comprehensive…
Privacy-preserving ad measurement with AdAttributionKit (SKAdNetwork's successor) — install and re-engagement attribution,…
Generate compelling App Store descriptions that convert browsers into users. Use when writing initial descriptions, improving…
Apple Search Ads campaign strategy for indie developers — paid acquisition, keyword bidding, budget planning, and ROAS…
Take a one-time in-app purchase from MISSING_METADATA to READY_TO_SUBMIT in App Store Connect — set its price schedule and…
Optimize app title, subtitle, and keywords for maximum App Store discoverability. Use when launching a new app, improving search…
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
Ask which skill or flow fits your situation. A router over the skills in this repo.