Skip to main content
rule

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.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdc
Open on GitHub

What 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.mdc

Frontmatter: description, globs, alwaysApply

Step 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

Similar IDE rules

Everything for Mobile →

From the same set234

The whole set →
vitest-unit-testing-cursorrules-prompt-file A Cursor rule that turns the agent into a Vitest and TypeScript test writer: it targets business logic and utilities, mocking dependencies with vi.mock. ★ 41,024repo stars vercel-deployment Enforces Vercel standards for Edge Runtime, serverless functions, and vercel.json. Useful when configuring routing and deployment pipelines. ★ 41,024repo stars vercel-deployment-cursorrules-prompt-file This rule guides an agent through Vercel deployment choices, from environment variables and serverless functions to caching and CI/CD. Use it when preparing a project for deployment. ★ 41,024repo stars unity-cursor-ai-c-cursorrules-prompt-file A Cursor rule that briefs the assistant on a Unity game project in C#: modular code, responsive mechanics, real-time performance. ★ 41,024repo stars typo3cms-extension-cursorrules-prompt-file This rule guides Cursor through TYPO3 CMS extension work, from PHP structure to tests and documentation. Use it when an agent is designing a new extension. ★ 41,024repo stars typescript A Cursor rule that pins down how the agent writes TypeScript: types, naming, error handling. Useful when several people touch the same codebase. ★ 41,024repo stars typescript-zod-tailwind-nextjs-cursorrules-prompt- Cursor coding standard for Next.js and TypeScript: enforces functional patterns, Zod validation, Shadcn UI, and desktop-first Tailwind CSS. ★ 41,024repo stars typescript-vuejs-cursorrules-prompt-file A Cursor rule that tells the agent how to write TypeScript inside Vue.js projects. Useful when you want edits across components to follow the same conventions. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor