uikit-guidelines-cursorrules-prompt-file — Cursor rule guide
A rule that enforces programmatic Swift UIKit layouts without Storyboards. It standardizes SnapKit for Auto Layout, isolates data models from UI views, and handles events with closures.
.cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdcWhat uikit-guidelines-cursorrules-prompt-file does
This prompt guides the AI assistant to write clean Swift code for UIKit without touching Storyboards or XIB files. All UI elements, such as UIView, UIButton, and UITableViewCell, are generated strictly in code. Auto Layout relies solely on SnapKit instead of NSLayoutConstraint while accounting for Dynamic Type and Safe Area boundaries.
Views stay completely decoupled from DTOs and models. The rule directs the agent to pass data via Factory, Builder, or ViewController patterns. External actions emit closures that pass self back to identify the event trigger. SnapKit must be installed in your project, or the generated code will fail to build. Existing code comments remain untouched.
What it helps with
- build programmatic iOS layouts without Storyboards
- replace verbose NSLayoutConstraint code with SnapKit DSL
- decouple Swift data models and DTOs from UIKit views
- handle UI interactions using closures that send component references
Example prompts for the agent
- Create a profile screen in UIKit with an avatar image and an edit button
- Build a custom news feed table cell configured via a factory
- Generate a reusable button that sends its tap event through a closure
How to install uikit-guidelines-cursorrules-prompt-file
Manually: put the files in place
.cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/uikit-guidelines-cursorrules-prompt-file.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/uikit-guidelines-cursorrules-prompt-file.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/uikit-guidelines-cursorrules-prompt-file.mdManually: put the files in place
.clinerules/uikit-guidelines-cursorrules-prompt-file.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about uikit-guidelines-cursorrules-prompt-file
How to install uikit-guidelines-cursorrules-prompt-file in Cursor?
Create a rule file at .cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdc in your repository and paste the prompt content into it.
What does uikit-guidelines-cursorrules-prompt-file do?
It enforces programmatic UIKit patterns in Swift, requiring SnapKit for layouts and forbidding Storyboards and direct model bindings inside views.
Is SnapKit required when using this rule?
Yes. The instructions explicitly disallow NSLayoutConstraint and mandate SnapKit for every constraint setup.
Source text
uikit-guidelines-cursorrules-prompt-file.mdc · CC0-1.0
--- description: "Cursor rules for UIKit development guidelines." globs: **/* alwaysApply: false --- you are an expert in coding with swift, iOS, UIKit. you always write maintainable code and clean code. focus on latest documentation and features. your descriptions should be short and concise. don't remove any comments. UIKit UI Design Principles: 1. Auto Layout: Implement responsive layouts using SnapKit only (avoid NSLayoutConstraint for better readability), support Dynamic Type and Safe Area 2. Programmatic UI: Avoid Storyboards/XIBs, implement all UI components directly in code (UIView, UIButton, UITableViewCell). Use view composition and custom view subclasses for reusability 3. UI Components must not directly access models or DTOs. Use ViewController, Factory, or Builder patterns following OOP/MVC/MVVM principles. Below are good and bad practice examples: good practice: ```swift let user = User(name: "Alice", email: "[email protected]") let factory = UserFactory() /// This way UserView doesn't access User model directly, following Apple's MVC principles let userView = factory.createUserView(user: user) ``` bad practice: ```swift let user = User(name: "Alice", email: "[email protected]") /// This exposes UserView to User model, violating MVC principles let userView = UserView(user: user) ``` 4. UI components should pass events using closures, and the closure must pass 'self' as a parameter to allow external objects to identify the source component ```swift class SampleView: UIView { var didTapButton: ((SampleView) -> Void)? private let button = UIButton() override init(frame: CGRect) { super.init(frame: frame) setupUI() button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) } private func setupUI() { // setup UI } @objc private func buttonTapped() { didTapButton?(self) } } ```
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules