This document provides comprehensive guidelines for using and developing Swift/iOS-focused Cursor rules.
- Introduction
- Rule Categories
- Using Rules
- Development Principles
- Best Practices
- Common Patterns
- Troubleshooting
Cursor Swift Rules is a collection of AI-powered development rules specifically designed for Swift and iOS development. These rules help maintain consistency, improve code quality, and accelerate development workflows.
- Automatic Swift best practices enforcement
- iOS-specific architectural patterns
- SwiftUI and UIKit integration guidance
- Testing and documentation automation
- Release and deployment assistance
with-swift.mdc: Swift language best practiceswith-ios.mdc: iOS platform patternswith-swiftui.mdc: SwiftUI-specific patternswith-uikit.mdc: UIKit-specific patterns
create-tests-swift.mdc: Swift test creationwith-tests.mdc: Test execution and analysistest-coverage.mdc: Coverage reporting
create-ios-release.mdc: iOS app releasecreate-release.mdc: General release managementwith-fastlane.mdc: Fastlane integration
create-docs.mdc: Documentation generationwith-jazzy.mdc: Jazzy documentationwith-docc.mdc: DocC integration
Rules can be activated in three ways:
-
Automatic Activation
// This will automatically activate with-swift.mdc class MySwiftClass { // Your code }
-
Manual Activation
@with-swift -
File Pattern Matching
.swiftfiles →with-swift.mdcTests/directory →create-tests-swift.mdc*.xcodeproj→with-ios.mdc
Combine multiple rules for comprehensive coverage:
@with-swift @with-swiftui @create-tests-swift
- Prioritize Swift idioms and patterns
- Leverage Swift's type system
- Follow Swift API design guidelines
- Consider iOS lifecycle
- Handle device capabilities
- Support multiple screen sizes
- Implement proper memory management
- Write testable code
- Include test coverage requirements
- Support both unit and UI testing
- Enable quick test feedback
- Maintain clear documentation
- Include usage examples
- Document edge cases
- Provide troubleshooting guides
-
Clear Activation Conditions
--- description: "Activates for SwiftUI view files" globs: ["*/Views/*.swift"] --- -
Specific Pattern Matching
filters: - type: file_change pattern: "*.swift" - type: content pattern: "struct.*View" -
Helpful Error Messages
action: | When encountering memory issues: 1. Check for retain cycles 2. Verify weak references 3. Inspect closure captures
-
Logical Grouping
.cursor/rules/ ├── swift/ │ ├── with-swift.mdc │ └── with-swiftui.mdc ├── testing/ │ └── create-tests-swift.mdc └── release/ └── create-ios-release.mdc -
Clear Naming
- Use descriptive prefixes
- Indicate primary purpose
- Follow naming conventions
action: |
Check for:
- Strong reference cycles
- Proper use of weak/unowned
- Closure capture lists
- Deinitialization
action: |
Verify:
- Main thread UI updates
- Proper layout constraints
- Accessibility support
- Dark mode compatibility
action: |
Ensure:
- Isolated test cases
- Proper mock objects
- Async test support
- Performance testing
-
Rule Not Activating
- Check file patterns
- Verify rule syntax
- Review activation conditions
-
Conflicting Rules
- Check rule priorities
- Review rule combinations
- Adjust activation conditions
-
Performance Issues
- Optimize pattern matching
- Reduce rule complexity
- Cache frequent operations
-
Enable debug logging:
--- debug: true --- -
Check rule activation:
cursor rules status
-
Verify rule syntax:
cursor rules lint
- Check our FAQ
- Join our community discussions
- Submit an issue
- Review existing rules for examples
Remember: The goal is to enhance Swift/iOS development workflow while maintaining code quality and consistency.