Skip to content

project rulesMobileswift

SwiftUI iOS Rules

Project rules for SwiftUI apps: @Observable models, NavigationStack routing, async/await with actors, previews and XCTest coverage.

npx workspacetemplates add swiftui-ios-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file19 lines · 1.2 KBFile
# Project rules: SwiftUI for iOS

## Views and state
- Keep views small and declarative. Move logic into an `@Observable` model marked `@MainActor`. Use `@State` to own a model, `@Bindable` for bindings, `@Environment` for shared dependencies.
- Extract a subview when a body passes about 40 lines. Avoid `AnyView`; prefer generics and `@ViewBuilder`.
- Use stable `Identifiable` ids in `ForEach`; never index-based identity for mutable lists.

## Navigation
- Use `NavigationStack` with a typed path and `navigationDestination(for:)`. Present sheets from state, not from imperative calls.

## Concurrency and data
- Use async/await. Call services from `.task { }`, which cancels with the view. Isolate shared mutable state in an `actor`. Make model types `Sendable`.
- Never force-unwrap or use `try!` outside tests. Surface failures as state the view renders.
- Put networking behind a protocol so tests can inject a fake. Keep secrets in Keychain.

## Quality
- Every view has a `#Preview` with sample data, including an empty and an error case.
- Write XCTest or Swift Testing tests for each model. Add accessibility labels and support Dynamic Type.
- Run `swift-format lint` and `xcodebuild test` on a simulator before finishing.

What it does

These rules set the shape of a SwiftUI codebase: thin views, observable models that own state, and navigation driven by data. They steer an agent away from patterns that fight the framework.

They also address Swift concurrency and testing, so network calls stay off the main thread and each model can be exercised without launching the UI.

Example

you › Show a list of recipes with a detail screen and pull to refresh

agent › The agent adds a RecipesModel, a NavigationStack with typed routes, refreshable async loading and tests using a fake service.

Questions

Does it target the Observation framework?
Yes, it assumes @Observable. For older deployment targets, swap in ObservableObject and keep the other rules.
Which test framework?
Either XCTest or Swift Testing works; pick one per target and keep to it.
  • Flutter Rules

    Project rulesflutter

    Free
  • Kotlin Android Rules

    Project ruleskotlin

    Free
  • React Native Expo Rules

    Project rulesreact-native

    Free
  • Flutter State Management

    Skillflutter

    Free