No. 133 Lower the entropy

You are an expert in coding with swift, iOS, UIKit. you…

You are an expert in coding with swift, iO.

  • Claude Code
  • Codex
  • Cursor
  • Lower the entropy

Prompt

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: "john@example.com")
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: "john@example.com")
/// 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)
    }
}
```

When to use

“You are an expert in coding with swift, iOS, UIKit. you…” fits when the code works but the structure is harder than the behavior, because it says “you are an expert in coding with swift, iOS, UIKit.”, and it is written to stay in force on later turns rather than to finish one task.

For “You are an expert in coding with swift, iOS, UIKit. you…”, the extra line you type is the requirement those steps ask for, for example “make src/cart.js return 0 on an empty cart and skip a line with no price”, and the file then starts at “Auto Layout: Implement responsive layouts using SnapKit only (avoid NSLayoutConstraint for better readability)”.

When not to use

Leave “You are an expert in coding with swift, iOS, UIKit. you…” unused when the change is a one-line typo or a red build you have not read, because “you are an expert in coding with swift, iOS, UIKit.” points the other way

How to run it

Claude Code

Claude Code loads “You are an expert in coding with swift, iOS, UIKit. you…” from .claude/rules on later sessions, so “you are an expert in coding with swift, iOS, UIKit.” survives a new chat, which a one-off paste does not.

Codex

Codex keeps “You are an expert in coding with swift, iOS, UIKit. you…” only if you put “you are an expert in coding with swift, iOS, UIKit.” in AGENTS.md, or in AGENTS.override.md beside the directory that should inherit it. A paste that is not saved is gone next thread.

Cursor

Cursor keeps “You are an expert in coding with swift, iOS, UIKit. you…” by saving “you are an expert in coding with swift, iOS, UIKit.” as .cursor/rules. The chat transcript alone will not reload it tomorrow.

Comparison

对比待补

This before-and-after was not run on this machine.

Related

来源:PatrickJS awesome-cursorrules · https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/uikit-guidelines-cursorrules-prompt-file.mdc · CC0-1.0 · 2026-12-01