swiftui-expert
Skill5 starsChanged 3 months agoMITView on GitHub
Use when working in a native iOS/SwiftUI project - *.swift files, an *.xcodeproj or Package.swift, Xcode schemes, or mentions of SwiftUI, Swift 6, @Observable, SwiftData, NavigationStack, actors, or Swift Testing. Builds views and features, wires Observation-based state, fixes Swift 6 strict-concurrency errors, models persistence with SwiftData, and writes Swift Testing/XCTest suites for iOS 18+ apps. Invoke for adding screens or view models, migrating ObservableObject to @Observable, resolving Sendable/actor-isolation compile errors, NavigationStack routing and deep links, async URLSession networking, diagnosing excess body re-evaluation, and UI-test-ready accessibility identifiers.
In this repository15 other files it gives its agents.
- docker-expertSkill
- engineering-rulesSkill
- fastapi-expertSkill
- fastify-expertSkill
- flutter-expertSkill
- go-expertSkill
- jetpack-compose-expertSkill
- mobile-qa-expertSkill
- nestjs-expertSkill
- playwright-expertSkill
- react-expertSkill
- react-native-expertSkill
- remix-expertSkill
- terraform-expertSkill
- vue-expertSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
Verify build: - Run xcodebuild -scheme <Scheme> -destination 'platform=iOS Simulator,name=iPhone 16' build (or swift build for a package).
- Very specific: line 33
Lint: - Run swiftlint (use swiftlint --strict if the project's CI does).
- Very specific: line 34
Test: - Write or update tests for the change (Swift Testing @Test/#expect for new tests.
- Very specific: line 139
Spawning
Task { await vm.load() }inonAppear: Use .task { await vm.load() } - it cancels automatically when the view disappears and …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI Expert
Turns Claude into a senior iOS engineer who ships Swift 6 / iOS 18+ SwiftUI - Observation-based state, strict concurrency that compiles, SwiftData, NavigationStack - instead of the ObservableObject/NavigationView idioms that dominate training data.
When to Use This Skill
- Building screens, components, or features in a SwiftUI app
- Wiring state with the Observation framework (
@Observable,@Bindable,@State) or migrating offObservableObject/@Published - Fixing Swift 6 strict-concurrency compile errors (Sendable, actor isolation,
@MainActor) - Navigation with
NavigationStack/NavigationPath: programmatic routing, deep links, split views - Persistence with SwiftData (
@Model,@Query) or deciding SwiftData vs Core Data - Async/await networking with URLSession and dependency injection via
@Environment - Diagnosing unnecessary
bodyre-evaluation, view-identity bugs, or slow lists - Writing Swift Testing (
@Test,#expect) and XCTest/XCUITest suites, including accessibility identifiers for UI testability
Core Workflow
- Analyze - Read the project first: deployment target and
SWIFT_VERSION/SWIFT_STRICT_CONCURRENCY(and Swift 6.2 default-isolation settings) in project.pbxproj orPackage.swift, existing state pattern (Observation vs legacy ObservableObject), navigation setup, persistence layer, and test targets. List schemes/simulators withxcodebuild -listandxcrun simctl list devices available. Match the project's conventions; propose migration only when the task is a migration. - Implement - Write the change with current idioms:
@Observableclasses owned by@Stateand injected via.environment(...), value-type views,NavigationStackwith typed paths, structured concurrency (async let,TaskGroup) over unstructuredTask {}, SwiftData@Model/@Querywhere the project uses it. Add.accessibilityIdentifier(...)to any interactive element a UI test will need. - Verify build - Run
xcodebuild -scheme <Scheme> -destination 'platform=iOS Simulator,name=iPhone 16' build(orswift buildfor a package); fix all reported issues and re-run until clean before proceeding. Treat concurrency warnings as errors - under Swift 6 language mode they are. - Lint - Run
swiftlint(useswiftlint --strictif the project's CI does); fix all reported issues and re-run until clean. Respect the project's.swiftlint.yml; do not disable rules inline to silence findings. - Test - Write or update tests for the change (Swift Testing
@Test/#expectfor new tests; keep existing XCTest suites in their framework), then runxcodebuild -scheme <Scheme> -destination 'platform=iOS Simulator,name=iPhone 16' test(orswift testfor a package); fix all failures and re-run until every test passes. - Prove it works - Exercise the changed flow: confirm the relevant
#Previewrenders the states you touched (loading/error/data), or build-and-run on a simulator (xcrun simctl launch) and walk the flow. For performance work, verify in Instruments (SwiftUI template: View Body / Cause & Effect) that body re-evaluation actually dropped.
Reference Guide
Load detailed guidance only when the task needs it:
| Topic | Reference | Load When |
Observation state: @Observable, @Bindable, @State, Environment DI, ObservableObject migration, view identity & re-evaluation | references/observation-state.md | Adding/refactoring app state or view models, bindings into observable models, migrating @Published, excess body re-runs, identity/animation bugs |
Swift 6 strict concurrency: actors, @MainActor, Sendable, common compile errors and their fixes, Swift 6.2 default isolation | references/swift6-concurrency.md | Any Sendable/isolation compile error, adding async code, background work, migrating a target to Swift 6 language mode |
Navigation: NavigationStack, NavigationPath, navigationDestination, NavigationSplitView, deep links, sheets | references/navigation.md | Adding routes/flows, programmatic or deep-link navigation, replacing NavigationView, back-stack bugs |
SwiftData: @Model, @Query, #Predicate, relationships, migration, CloudKit, and when Core Data is still right | references/swiftdata-persistence.md | Modeling or querying persisted data, schema migration, SwiftData-vs-Core-Data decisions, sync |
Testing: Swift Testing (@Test, #expect, #require, suites, parameterized), XCTest/XCUITest, accessibility identifiers, previews as a dev loop | references/testing.md | Writing or fixing any test, choosing Swift Testing vs XCTest, UI-test element queries, preview setup |
Key Patterns
Observable model + Environment injection (the default architecture):
@Observable @MainActor
final class StoreModel {
var products: [Product] = []
var isLoading = false
private let client: APIClient
init(client: APIClient) { self.client = client }
func load() async { /* ... */ }
}
@main struct ShopApp: App {
@State private var store = StoreModel(client: .live) // @State owns it
var body: some Scene {
WindowGroup { RootView().environment(store) } // .environment, not .environmentObject
}
}
struct RootView: View {
@Environment(StoreModel.self) private var store // typed, no property wrapper protocol
var body: some View {
@Bindable var store = store // bindings into an environment model
ProductList(products: store.products)
.searchable(text: $store.query)
.task { await store.load() }
}
}NavigationStack with a typed path (programmatic + deep-linkable):
enum Route: Hashable { case product(Product.ID), cart, settings }
struct ContentView: View {
@State private var path: [Route] = []
var body: some View {
NavigationStack(path: $path) {
HomeView()
.navigationDestination(for: Route.self) { route in
switch route {
case .product(let id): ProductView(id: id)
case .cart: CartView()
case .settings: SettingsView()
}
}
}
.onOpenURL { url in path = Route.parse(url) } // deep link = set the path
}
}Async networking, checked and typed:
func fetch<T: Decodable>(_ type: T.Type, from url: URL) async throws -> T {
let (data, response) = try await URLSession.shared.data(from: url)
guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else {
throw APIError.badStatus((response as? HTTPURLResponse)?.statusCode ?? -1)
}
return try JSONDecoder().decode(T.self, from: data)
}Swift Testing over XCTest for new unit tests:
import Testing
@Suite struct PriceTests {
@Test(arguments: [(100, "₹100"), (0, "Free")])
func formats(amount: Int, expected: String) {
#expect(Price(amount).display == expected)
}
@Test func loadsProducts() async throws {
let store = StoreModel(client: .stub)
await store.load()
let first = try #require(store.products.first) // unwraps or fails the test
#expect(first.name == "Widget")
}
}Common Mistakes
- Writing
ObservableObject/@Published/@StateObject/@EnvironmentObjectin new code. On iOS 17+ use@Observablewith@Stateownership,.environment(...), and@Environment(Type.self).@Bindable(not@Binding) creates bindings into an observable class. Keep the legacy stack only in files that already use it, or in a deliberate migration. - Spawning
Task { await vm.load() }inonAppear. Use.task { await vm.load() }- it cancels automatically when the view disappears and re-runs with.task(id:)when inputs change. Unstructured tasks leak past the view's lifetime. - Silencing Swift 6 concurrency errors with
@unchecked Sendableornonisolated(unsafe). These erase the compiler's proof, and are almost never the fix. Isolate the type (@MainActorfor UI-facing models,actorfor shared mutable state) or make it aSendablevalue type; see the concurrency reference for the error-to-fix table. NavigationView,.navigationBarItems,NavigationLink(destination:isActive:). All deprecated. UseNavigationStack/NavigationSplitView,.toolbar, and value-basedNavigationLink(value:)+navigationDestination(for:).- Conditional view branches that destroy identity.
if isDetailed { BigCard() } else { SmallCard() }tears down state and animations; prefer one view whose modifiers vary. Never useAnyVieworid(UUID())to "fix" refresh issues - randomidrecreates the subtree every render. - Passing whole
@Observablemodels through many layers "for convenience". Observation tracks per-property reads, so body re-runs only for properties actually read - but passing the model everywhere invites accidental reads. Pass the values a subview needs; keep models at feature roots. - Fetching SwiftData manually in
onAppearand storing results in@State. Use@Query- it live-updates on context changes and sorts/filters with#Predicateat the store level. - Testing async view-model code with
XCTestExpectationpolling. Swift Testing'sasynctest functions plusconfirmation(...)cover callbacks;await store.load()directly - nowaitForExpectations, nosleep.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

