uikit

UIKit

UIKit framework patterns for iOS and macOS Catalyst application development

Details

Language / Topic
objective-cObjective-C
Category
framework
Compatible Frameworks
uikit

Rules

balanced
- Always update UIKit components on the main thread — dispatch UI updates with `dispatch_async(dispatch_get_main_queue(), ^{ ... })` when coming from background threads.
- Use `UITableView` and `UICollectionView` with `registerClass:forCellReuseIdentifier:` and `dequeueReusableCellWithIdentifier:forIndexPath:` — never allocate cells manually in `cellForRowAtIndexPath:`.
- Override `traitCollectionDidChange:` to respond to size class and appearance changes — do not hardcode dimensions or colors that need to adapt.
- Use `UIStackView` for linear layouts instead of manual `NSLayoutConstraint` arithmetic — it handles spacing, distribution, and hidden subview removal automatically.
- Use `NSLayoutConstraint` with `constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:` or visual format language rather than setting `frame` directly.
- Use `UIView.animate(withDuration:...)` for simple property animations and `UIViewPropertyAnimator` for interruptible, reversible animations.
- Implement `UIContentConfiguration` and `UIBackgroundConfiguration` for custom cell content in iOS 14+ instead of subclassing `UITableViewCell` directly.