Cursor rules for SwiftUI: set them up so Cursor writes current Swift
Updated
Cursor writes SwiftUI from whatever its model learned, which often means ObservableObject everywhere, onAppear { Task { … } } and deployment targets you do not support. Project rules fix that by giving the agent your conventions on every request. This guide shows how Cursor rules work for a Swift project, how to scope them to .swift files, which public rule files exist, and where an AGENTS.md or an agent skill is the better tool.
How Cursor rules work (the short version)
From the Cursor rules documentation:
Project rules live in
.cursor/rules/and are version-controlled.They must use the
.mdcextension. A plain.mdfile in.cursor/rulesis ignored because it has no frontmatter.The frontmatter fields
description,globsandalwaysApplydecide when a rule is included:
alwaysApply | description | globs | Behavior |
|---|---|---|---|
true | – | – | Always included |
false | – | set | Auto-attached when a matching file is in context |
false | set | – | Agent decides from the description |
false | – | – | Only when you @-mention the rule |
Cursor also supports User Rules (global), Team Rules (Team/Enterprise plans) and a plain
AGENTS.mdin the project root as a simpler alternative to.cursor/rules.
A minimal SwiftUI rule, scoped to Swift files
Use a glob so the rule only loads when Swift code is involved. The **/*.ext pattern matches files in any directory, per the same docs.
markdown
---
description: SwiftUI conventions for this app
globs: **/*.swift
alwaysApply: false
---
- Deployment target: iOS 17. Use @Observable models, not ObservableObject.
- Async work tied to a view goes in .task, not Task {} inside onAppear.
- Keep view bodies small; extract subviews into separate structs.
- New tests use Swift Testing (import Testing).Save it as .cursor/rules/swiftui.mdc. The content above is an example; write rules that match your app. Keep each rule concrete enough that you could check whether the output follows it.
Why the deployment target line matters: @Observable (the Observation framework) is available from iOS 17.0 according to Apple's documentation. If your rule says "use @Observable" but the app supports iOS 16, Cursor will produce code that does not compile for your target. Put the target in the rule.
Ready-made rule files for Swift and SwiftUI
| Name | Format | Scope | What it pushes | Source |
|---|---|---|---|---|
| SwiftUI Guidelines (awesome-cursorrules) | .mdc | globs: **/* | Swift 6 strict concurrency, iOS 15+, MVVM/Clean Architecture, @StateObject/@ObservedObject, .task(id:) over .onAppear, body ≤ 50 lines | GitHub |
| Swift UIKit (awesome-cursorrules) | .mdc | globs: **/* | UIKit + MVVM + RxSwift/RxCocoa | GitHub |
| SwiftAgents (Paul Hudson) | AGENTS.md | whole repo | Modern APIs, iOS 26+ | GitHub |
The awesome-cursorrules repository had 40,914 GitHub stars and a CC0-1.0 license on 2026-10-16; SwiftAgents had 1,467 stars (no license declared on GitHub).
Read before you copy. Two things we noticed in the files themselves:
Both awesome-cursorrules files ship with
globs: **/*, so they attach to every file in the repo, including JSON and scripts. Change the glob to**/*.swiftif you only want them on Swift code.The SwiftUI Guidelines file targets iOS 15+ and teaches the
ObservableObjectwrappers (@StateObject,@ObservedObject,@EnvironmentObject). That is correct for iOS 15/16 apps; if your floor is iOS 17+, edit those lines toward@Observableor the rule will pull Cursor back to the older pattern.
Rules vs AGENTS.md vs skills
Cursor project rule (.mdc) | AGENTS.md | Agent skill (SKILL.md) | |
|---|---|---|---|
| Loaded | Always, by glob, by description, or on @-mention | As project instructions | When the agent decides it is relevant |
| Best for | Short conventions per file type | One file shared by several agents | Long, task-specific guidance (e.g. a SwiftUI review checklist) |
| Works in other tools | Cursor | Cursor, Codex, Claude Code (reads it when no CLAUDE.md exists, v2.1.277+, per Claude Code docs) | Many agents via the Agent Skills format |
A practical split for an iOS repo: put the 10–20 lines every request needs (target, architecture, testing framework) in a rule or AGENTS.md, and install a skill for deep SwiftUI knowledge. Skills in the catalog that list Cursor support:
SwiftUI Pro: navigation, layout, animation, state, VoiceOver, deprecated API.
SwiftUI Expert: which property wrapper holds a value, how to split a screen.
SwiftUI Design Skill: rules against generic AI-looking UI.
Apple Skills (Prisma Labs): iOS 26+ APIs and Liquid Glass; README shows
npx skills add Prisma-Labs-Dev/apple-skills --agent cursor --skill '*' -g -y.
Moving rules between Cursor and Claude Code
If your team uses both tools, you do not need two sets of rules. Claude Code's /init reads Cursor rules in .cursor/rules/ or .cursorrules and folds the relevant parts into the generated CLAUDE.md (Claude Code docs). Claude Code also has its own path-scoped rules in .claude/rules/*.md with a paths: field, the equivalent of Cursor's globs. See Claude Code for iOS development.
Checklist for a good SwiftUI rule
States the minimum iOS version and Swift language mode.
Names the state-management pattern you actually use.
Says which test framework new tests use.
Is scoped with
globs: **/*.swift(oralwaysApply: trueonly if it is short).Contains no instructions that contradict your other rules or
AGENTS.md.
FAQ
- Where do Cursor rules go in an iOS project?
- In .cursor/rules/ at the repository root, as .mdc files with frontmatter. A plain .md file there is ignored; use AGENTS.md if you want plain markdown.
- What glob should a SwiftUI rule use?
- **/*.swift attaches the rule whenever a Swift file is in context. Set alwaysApply: false so it does not load for unrelated files.
- Is .cursorrules still supported?
- Cursor's current docs describe project rules in .cursor/rules and AGENTS.md. Claude Code's /init can still read a legacy .cursorrules file when migrating.
- Should I use a rule or a skill for SwiftUI best practices?
- Use a short rule for project facts (iOS target, architecture) and a skill for broad SwiftUI guidance, which only loads when relevant and so costs less context.