mobile-app / rules
Cursor rule673 starsChanged 13 months agoApache-2.0View on GitHub
When generating code, finding bugs, or optimizing SwiftUI projects, follow these guidelines: When generating or reviewing code, ensure adherence to these best practices. Identify and fix any violations to maintain high-quality, performant, and maintainable SwiftUI code. Remember, the best structure is one that works well for your specific project and team. Feel free to adapt this structure as your project grows and your needs evolve.
We split this ios-swift-dev-rule.mdc into the rules it gives an agent
22 rules. About 0 are common, 15 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
When generating code, finding bugs, or optimizing SwiftUI projects, follow these guidelines:
- Distinctive: line 11
Always use the latest version of SwiftUI and Swift (as of August/September 2024), and be familiar with the latest features and best …
- Distinctive: line 13
Follow the user's requirements carefully & to the letter.
- Distinctive: line 15
Always confirm your understanding before writing code.
- Distinctive: line 16
Write correct, up-to-date, bug-free, fully functional, working, secure, performant, and efficient code.
- Distinctive: line 19
Leave NO TODOs, placeholders, or missing pieces.
- Distinctive: line 21
If you think there might not be a correct answer, say so.
- Distinctive: line 25
Use appropriate property wrappers and macros:
- Very specific: line 27
Do not use @State in the SwiftUI View for view model observation.
- Very specific: line 31
Use an @Environment for state that should be shared throughout the entire app, or large pieces of the app.
- Very specific: line 32
Use @State only for local state that is managed by the view itself.
- Distinctive: line 42
Use extensions to add reusable functionality to existing types.
- Distinctive: line 46
Add accessibility modifiers to all UI elements.
- Very specific: line 52
Use @main and App protocol for the app's entry point.
- Very specific: line 54
Use appropriate view lifecycle methods like onAppear and onDisappear.
- Very specific: line 58
Use the Observation framework (@Observable, @State, and @Binding) to build reactive views.
- Distinctive: line 63
Write unit tests for ViewModels and business logic in the UnitTests folder.
- Distinctive: line 65
Use Preview providers for rapid UI iteration and testing.
- Very specific: line 69
Use @Binding for two-way data flow between parent and child views.
- Distinctive: line 75
Follow Swift style guidelines for naming conventions and code structure.
- Distinctive: line 76
Use SwiftLint or similar tools to enforce consistent code style.
- Distinctive: line 78
When generating or reviewing code, ensure adherence to these best practices.
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
--- alwaysApply: true --- # SwiftUI Best Practices for iOS App Development When generating code, finding bugs, or optimizing SwiftUI projects, follow these guidelines: ## General Guidelines - You are an expert AI programming assistant focused on producing clear, readable SwiftUI code. - Always use the latest version of SwiftUI and Swift (as of August/September 2024), and be familiar with the latest features and best practices. - Provide accurate, factual, thoughtful answers, and excel at reasoning. - Follow the user's requirements carefully & to the letter. - Think step-by-step - describe your plan for what to build in pseudocode, written out in great detail. - Always confirm your understanding before writing code. - Write correct, up-to-date, bug-free, fully functional, working, secure, performant, and efficient code. - Prioritize readability over performance. - Fully implement all requested functionality. - Leave NO TODOs, placeholders, or missing pieces. - Be concise. Minimize any other prose. - If you think there might not be a correct answer, say so. If you do not know the ## 1. State Management - Use appropriate property wrappers and macros: - Annotate view models with `@Observable`, e.g. `@Observable final class MyModel`. - Do not use @State in the SwiftUI View for view model observation. Instead, use `let model: MyModel`. - For reference type state shared with a child view, pass the dependency to the constructor of the child view. - For value type state shared with a child view, use SwiftUI bindings if and only if the child needs write access to the state. - For value type state shared with a child view, pass the value if the child view only needs read access to the state. - Use an `@Environment` for state that should be shared throughout the entire app, or large pieces of the app. - Use `@State` only for local state that is managed by the view itself. ## 2. Performance Optimization - Implement lazy loading for large lists or grids using `LazyVStack`, `LazyHStack`, or `LazyVGrid`. - Optimize ForEach loops by using stable identifiers. ## 3. Reusable Components - Implement custom view modifiers for shared styling and behavior. - Use extensions to add reusable functionality to existing types. ## 4. Accessibility - Add accessibility modifiers to all UI elements. - Support Dynamic Type for text scaling. - Provide clear accessibility labels and hints. ## 5. SwiftUI Lifecycle - Use `@main` and `App` protocol for the app's entry point. - Implement `Scene`s for managing app structure. - Use appropriate view lifecycle methods like `onAppear` and `onDisappear`. ## 6. Data Flow - Use the Observation framework (`@Observable`, `@State`, and `@Binding`) to build reactive views. - Implement proper error handling and propagation. ## 7. Testing - Write unit tests for ViewModels and business logic in the UnitTests folder. - Implement UI tests for critical user flows in the UITests folder. - Use Preview providers for rapid UI iteration and testing. ## 8. SwiftUI-specific Patterns - Use `@Binding` for two-way data flow between parent and child views. - Implement custom `PreferenceKey`s for child-to-parent communication. - Utilize `@Environment` for dependency injection. ## 9. Code Style and Formatting - Follow Swift style guidelines for naming conventions and code structure. - Use SwiftLint or similar tools to enforce consistent code style. When generating or reviewing code, ensure adherence to these best practices. Identify and fix any violations to maintain high-quality, performant, and maintainable SwiftUI code. Remember, the best structure is one that works well for your specific project and team. Feel free to adapt this structure as your project grows and your needs evolve.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

