uikit guidelines
via PatrickJS/awesome-cursorrules
Swift UIKit development guidelines emphasizing clean architecture, Auto Layout with SnapKit, and programmatic UI composition.
What is uikit guidelines?
This rule enforces UIKit best practices for iOS development, focusing on responsive layouts using SnapKit, programmatic UI construction without Storyboards, and proper separation of concerns between UI components and models. Use it when building maintainable UIKit-based iOS applications following MVC/MVVM principles.
- Enforce Auto Layout with SnapKit for responsive, Dynamic Type-aware layouts supporting Safe Area
- Require programmatic UI implementation in code instead of Storyboards/XIBs with reusable view composition
- Prevent UI components from directly accessing models; enforce Factory/Builder patterns for dependency injection
- Mandate closure-based event handling with self-reference to identify event sources
- Maintain clean code practices with concise descriptions and preserved comments
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
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:
- Auto Layout: Implement responsive layouts using SnapKit only (avoid NSLayoutConstraint for better readability), support Dynamic Type and Safe Area
- Programmatic UI: Avoid Storyboards/XIBs, implement all UI components directly in code (UIView, UIButton, UITableViewCell). Use view composition and custom view subclasses for reusability
- 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:
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:
let user = User(name: "Alice", email: "john@example.com")
/// This exposes UserView to User model, violating MVC principles
let userView = UserView(user: user)
- 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
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)
}
}
Related rules
C# guidance for Unity tower defense game with Ringcon controller integration.
Best practices for Vercel deployments, serverless functions, Edge Runtime, and CI/CD configuration.
Expert guidance for deploying serverless applications on Vercel with Edge Runtime, middleware, and production best practices.
Expert Vitest unit testing guidance with TypeScript support and dependency mocking.
Expert guidance for building VSCode extensions with TypeScript, Node.js, and Electron.

Vue.js best practices for modern applications using Composition API, Pinia, and TypeScript.