← Back to Presets
🍎

Swift + SwiftUI Rules

Native iOS/macOS development with SwiftUI

SwiftSwiftUIiOSmacOS
.cursorrules
# Role
You are an expert Swift developer building native iOS and macOS apps with SwiftUI.

# Tech Stack
- Swift 5.9+
- SwiftUI
- Swift Data
- Combine
- Xcode 16

# Code Conventions
- Use SwiftUI as the primary UI framework.
- Use Swift Data for persistence (replaces Core Data).
- Follow MVVM architecture with `@Observable` macro.
- Use Swift concurrency (async/await, actors) for async work.
- Use `NavigationStack` for navigation.
- Keep views small — extract subviews into separate structs.
- Use `@Environment` and `@State` property wrappers appropriately.
- Use Swift Package Manager for dependencies.

# Code Style Preferences
- Use TypeScript strict mode. Define types for all variables, parameters, and return values.
- Never use the `any` type. Use `unknown` if the type is truly uncertain, then narrow it.
- Use `const` by default. Only use `let` when reassignment is needed. Never use `var`.
- Always handle errors explicitly. Use try/catch for async operations. Never silently swallow errors.
- Use early returns (guard clauses) to reduce nesting and improve readability.
- Use descriptive, meaningful names for variables, functions, and classes. Avoid abbreviations.
- Keep functions small and focused. Each function should do one thing. Aim for under 50 lines.

# What to Avoid
- Do not use UIKit unless SwiftUI cannot handle the requirement.
- Do not force-unwrap optionals — use guard/if-let.
- Do not use massive view bodies — extract components.
- Do not ignore Swift concurrency warnings.

About Swift + SwiftUI AI Rules

AI coding rules files help your AI assistant (Cursor, Windsurf, Claude Code, GitHub Copilot, or Cline) understand your project's conventions, tech stack, and coding standards. This ensures the AI generates code that matches your team's style and follows best practices for SwiftUI.

This preset is designed for Swift + SwiftUI projects and includes rules for:

  • Use SwiftUI as the primary UI framework.
  • Use Swift Data for persistence (replaces Core Data).
  • Follow MVVM architecture with `@Observable` macro.
  • Use Swift concurrency (async/await, actors) for async work.
  • Use `NavigationStack` for navigation.

Simply select your preferred AI IDE format above, then copy or download the generated rules file. Place it in your project's root directory and your AI assistant will automatically follow these conventions.

Get This Preset for a Specific IDE

Other Presets You Might Like