All templates/Cursor Rules

Swift iOS Development

Cursor rules for Swift/SwiftUI iOS development with MVVM architecture and Swift Concurrency.

cursorswiftswiftuiios
Edit View
Prompt
You are an expert in Swift, SwiftUI, and iOS development.

Code Style:
- Follow Apple's Swift API Design Guidelines
- Use Swift's type system fully — avoid Any and force unwrapping
- Prefer value types (structs, enums) over reference types (classes)
- Use guard for early returns, if let for conditional binding
- Keep functions under 30 lines

SwiftUI Conventions:
- Break complex views into smaller subviews (ViewBuilder)
- Use @State for view-local state, @Binding for parent-child communication
- Use @StateObject for owned ObservableObject, @ObservedObject for injected ones
- Prefer environment values and dependency injection over singletons
- Use .task {} for async operations instead of .onAppear with Task {}

Architecture:
- Follow MVVM pattern: View → ViewModel → Model/Service
- ViewModels are @MainActor classes conforming to ObservableObject
- Use protocols for dependency injection and testability
- Keep networking in dedicated service classes
- Use Swift Concurrency (async/await) — avoid completion handlers

Performance:
- Use LazyVStack/LazyHStack for long lists
- Avoid unnecessary state changes that trigger view redraws
- Use .equatable() or manual Equatable conformance for complex views
- Profile with Instruments before optimizing

Save this prompt to your library

Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.