Skip to content
SwiftSkills

Cursor rules for SwiftUI: set them up so Cursor writes current Swift

To make Cursor write current SwiftUI, save a short project rule as .cursor/rules/swiftui.mdc with globs: **/*.swift, stating your iOS target, architecture and test framework. The ready-made SwiftUI Guidelines rule from awesome-cursorrules is CC0-licensed but targets iOS 15+. For deeper SwiftUI knowledge, add a skill such as SwiftUI Pro or SwiftUI Expert.

Last 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.

Browse all Swift rules and skill packs →

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 .mdc extension. A plain .md file in .cursor/rules is ignored because it has no frontmatter.

  • The frontmatter fields description, globs and alwaysApply decide when a rule is included:

alwaysApplydescriptionglobsBehavior
true––Always included
false–setAuto-attached when a matching file is in context
falseset–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.md in 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 rules and skills

NameTypeFormat / load behaviourWorks in CursorLicenseStars (2026-10-18)
SwiftUI Guidelines (awesome-cursorrules)Rule.mdc, globs: **/*, iOS 15+YesCC0-1.040,950 (whole repo)
Swift UIKit (awesome-cursorrules)Rule.mdc, globs: **/*, UIKit + RxSwiftYesCC0-1.040,950 (whole repo)
SwiftUI ProSkillSKILL.md, loaded when relevantYes (catalog tools)MIT6,204
SwiftUI ExpertSkillSKILL.mdYesMIT3,713
Apple Skills (Prisma Labs)SkillSKILL.md, --agent cursorYesMIT346
SwiftUI Design SkillSkillSKILL.mdYesMIT208

Stars from the GitHub API, checked on 2026-10-18. License as declared on GitHub and in our catalog.

Read before you copy. Two things we noticed in the files themselves:

  1. Both awesome-cursorrules files ship with globs: **/*, so they attach to every file in the repo, including JSON and scripts. Change the glob to **/*.swift if you only want them on Swift code.

  2. The SwiftUI Guidelines file targets iOS 15+ and teaches the ObservableObject wrappers (@StateObject, @ObservedObject, @EnvironmentObject). That is correct for iOS 15/16 apps; if your floor is iOS 17+, edit those lines toward @Observable or the rule will pull Cursor back to the older pattern.

Rules vs AGENTS.md vs skills

Cursor project rule (.mdc)AGENTS.mdAgent skill (SKILL.md)
LoadedAlways, by glob, by description, or on @-mentionAs project instructionsWhen the agent decides it is relevant
Best forShort conventions per file typeOne file shared by several agentsLong, task-specific guidance (e.g. a SwiftUI review checklist)
Works in other toolsCursorCursor, 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. The table above lists the rules and skills whose catalog entries include Cursor. Setting up Cursor for iOS (build, autocomplete, MCP)? Setup guide → For VoiceOver and Dynamic Type, see accessibility audits with AI agents. For models and queries, see SwiftData with AI agents.

Browse SwiftUI agent skills →

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. For the concurrency settings the agent cannot see, see Swift 6 concurrency with AI agents.

  • Names the state-management pattern you actually use.

  • Says which test framework new tests use.

  • Is scoped with globs: **/*.swift (or alwaysApply: true only 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.
Do Cursor rules for SwiftUI work in Claude Code or Codex?
Not directly. .mdc rules are Cursor-specific. For several agents, put shared rules in AGENTS.md, which Cursor, Codex and Claude Code (when no CLAUDE.md exists) read. Claude Code's /init can also read existing Cursor rules.