Home › All rules › Community › Uikit Guidelines Cursor Rules

Uikit Guidelines Cursor Rules

Cursor rules for UIKit development guidelines.

CursorSwift / SwiftUICommunity (CC0)

How to use

Save this as .cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdc in your project, commit it, and Cursor will load it. Review it first: community files can be opinionated or out of date.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/uikit-guidelines-cursorrules-prompt-file.mdcDownload  
---
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)
    }
}
```

More: Swift / SwiftUI rules · all community rules

Related rules

SwiftUI iOS app CLAUDE.md

CLAUDE.md for SwiftUI apps on iOS 18+ with Swift 6 strict concurrency, @Observable, SwiftData, and Swift Testing.

Claude Code (CLAUDE.md)Swift / SwiftUI

Swift Uikit Cursor Rules

Cursor rules for Swift Uikit.

CursorSwift / SwiftUICommunity (CC0)

Swiftui Guidelines Cursor Rules

Cursor rules for SwiftUI development guidelines.

CursorSwift / SwiftUICommunity (CC0)

Swift Mcp Server Copilot Instructions

Best practices and patterns for building Model Context Protocol (MCP) servers in Swift using the official MCP Swift SDK package.

GitHub CopilotSwift / SwiftUICommunity (MIT)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.