uikit-expert
Write, review, or improve UIKit code following best practices for view controller lifecycle, Auto Layout, collection views, navigation, animation, memory management, and modern iOS 18–26 APIs. Use when building new UIKit features, refactoring existing views or view controllers, reviewing code quality, adopting modern UIKit patterns (diffable data sources, compositional layout, cell configuration), or bridging UIKit with SwiftUI. Does not cover SwiftUI-only code.
How do I install this agent skill?
npx skills add https://github.com/ivan-magda/uikit-expert-skill --skill uikit-expertIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill is a comprehensive technical guide designed to teach AI agents how to write, review, and improve UIKit code. It contains extensive best practices for iOS development, including memory management, performance optimization, and modern API usage, without any malicious patterns or security risks.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
- Runlayerwarn
10/15 files flagged
What does this agent skill do?
UIKit Expert Skill
Overview
Favor native APIs and Apple's documented guidance. Operating principles: facts over architecture (no MVVM/VIPER/Coordinator mandates, but do separate business logic for testability); correctness first, then performance; reserve "always"/"never" for correctness, use "suggest"/"consider" for optional optimizations.
Reference files include step-by-step tool walkthroughs (Instruments, Memory Graph Debugger, LLDB) as developer documentation. In responses, name the relevant tool (e.g. "consider profiling with Instruments") instead of reproducing the steps.
Workflows
All three modes draw on the same Core Guidelines below; each topic links to its reference file there.
Before any mode, check the project's deployment target (IPHONEOS_DEPLOYMENT_TARGET, or platforms in Package.swift). Each guideline notes its minimum iOS version: use the API directly when the target is at or above it, otherwise gate it with #available and keep the older API as the fallback.
Pick the entry point:
- Review — Walk the Review Checklist as pass/fail gates. For any failure, fix per the matching Core Guideline. Prioritize correctness gates (lifecycle, Auto Layout, memory, concurrency) over style; treat performance items as optional.
- Improve — For each issue, apply the modern replacement from the Deprecated → Modern table and the matching Core Guideline. Present performance work (downsampling, prefetching, constraint-churn fixes) as optional optimizations, never mandates.
- Implement new — Build in this order, applying the relevant Core Guideline at each step:
- Design data flow — owned state, injected dependencies, model layer
- Lifecycle — one-time setup in
viewDidLoad, geometry inviewIsAppearing - Auto Layout — batch activation, zero churn
- Collection views — DiffableDataSource + CompositionalLayout + CellRegistration
- Navigation — all 4 appearance slots, concurrent-transition guards
- Animation, memory (
[weak self], Task cancellation), concurrency (@MainActor) - Interop, image loading, keyboard, Dynamic Type / VoiceOver / dark mode
- Gate every API newer than the deployment target (not only iOS 26+ features) with
#availableand a fallback
Core Guidelines
View Controller Lifecycle — see references/view-controller-lifecycle.md
- Use
viewDidLoadfor one-time setup: subviews, constraints, delegates — NOT geometry - Use
viewIsAppearing(back-deployed iOS 13+) for geometry-dependent work, trait-based layout, scroll-to-item viewDidLayoutSubviewsfires multiple times — use only for lightweight layer frame adjustmentsviewWillAppearis limited to transition coordinator animations and balanced notification registration- Always call
superin lifecycle overrides — except aloadViewoverride that builds the view hierarchy itself, which must not callsuper - Child VC containment:
addChild→addSubview→didMove(toParent:)— in that exact order - Verify deallocation with
deinitlogging during development
Auto Layout — see references/auto-layout.md
- Always set
translatesAutoresizingMaskIntoConstraints = falseon views you position with your own constraints — not on views UIKit positions for you (a pushed or presented controller's rootview, a cell'scontentView) - Prefer
NSLayoutConstraint.activate([])over setting.isActive = trueone constraint at a time (one batch for the layout engine) - Create constraints once, then toggle
isActiveor modify.constant— avoid removing and recreating them - Never change priority from/to
.required(1000) at runtime — use 999 - Animate constraints: update constant → call
layoutIfNeeded()inside animation block on superview - iOS 26+: use
.flushUpdatesoption to simplify constraint animation - Avoid deeply nested UIStackViews in reusable cells
- Set
constraint.identifieron key constraints soUnable to simultaneously satisfy constraintslogs are readable
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false // required on programmatic views
view.addSubview(label)
NSLayoutConstraint.activate([ // one batch = one solve pass
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
label.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
Collection Views & Data Sources — see references/modern-collection-views.md, references/cell-configuration.md, references/list-performance.md
- Use
UICollectionViewDiffableDataSourcewith stable identifiers (UUID/database ID, not full model structs) - Use
reconfigureItems(iOS 15+) for content updates,reloadItemsonly when cell type changes; with observation tracking enabled (iOS 18+ opt-in, default on iOS 26),@Observablereads inconfigurationUpdateHandlerrefresh the cell without a snapshot - Use
applySnapshotUsingReloadDatafor initial population (bypasses diffing) - Use
UICollectionViewCompositionalLayoutfor any non-trivial layout - Use
UICollectionView.CellRegistration— no string identifiers, no manual casting - Use
UIContentConfigurationfor cell content andUIBackgroundConfigurationfor cell backgrounds - Use
configurationUpdateHandlerfor state-driven styling (selection, highlight)
// Store the registration once — never create it inside the cell provider (crashes on iOS 15+).
private lazy var cellRegistration = UICollectionView.CellRegistration<PhotoCell, Photo> { cell, _, photo in
cell.configure(with: photo)
}
// Data source is keyed by the stable ID, so the provider receives an id — look up the model, then configure with it.
dataSource = .init(collectionView: collectionView) { [weak self] cv, indexPath, id in
guard let self, let photo = self.photo(for: id) else { return nil }
return cv.dequeueConfiguredReusableCell(using: self.cellRegistration, for: indexPath, item: photo)
}
var snapshot = NSDiffableDataSourceSnapshot<Section, Photo.ID>()
snapshot.appendSections([.main])
snapshot.appendItems(photos.map(\.id))
dataSource.apply(snapshot, animatingDifferences: true)
Navigation — see references/navigation-patterns.md
- Configure all 4
UINavigationBarAppearanceslots (standard, scrollEdge, compact, compactScrollEdge) - Set appearance on
navigationItem(per-VC) inviewDidLoad, not onnavigationBarinviewWillAppear - Use
setViewControllers(_:animated:)for deep links — not sequential push calls - Guard against concurrent transitions — check
transitionCoordinatorbefore push/pop - Set
prefersLargeTitlesonce on the bar; uselargeTitleDisplayModeper VC
Animation — see references/animation-patterns.md
UIView.animate— simple one-shot animations; checkfinishedin completionUIViewPropertyAnimator— gesture-driven, interruptible; respect state machine (inactive → active → stopped)CABasicAnimation— layer-only properties (cornerRadius, shadow, 3D transforms); set model value first- iOS 17+ spring API:
UIView.animate(springDuration:bounce:)aligns with SwiftUI - Constraint animation: flush layout → update constant → animate
layoutIfNeeded()on superview
Memory Management — see references/memory-management.md
- Default to
[weak self]in escaping closures that are stored or long-lived (callbacks, observers, timers, stored handlers). It is not needed where the closure runs once and is released (UIView.animate,DispatchQueue.main.async) or where the API hands you the object (theself: Selfparameter of aregisterForTraitChangeshandler) - Timer: use block-based API with
[weak self]; start it in an appearance callback (viewIsAppearing) and invalidate inviewWillDisappear, so it restarts when the screen reappears - CADisplayLink: use weak proxy pattern (no block-based API available); start and invalidate it with the same appearance pairing
- NotificationCenter:
[weak self]in closure, remove observer indeinit - Nested closures: re-capture
[weak self]in stored inner closures - Delegates: always
weak var delegate: SomeDelegate?withAnyObjectconstraint - Verify deallocation with
deinit— if never called, a retain cycle exists
Concurrency — see references/concurrency-main-thread.md
UIViewControlleris@MainActor— all subclass methods are implicitly main-actor- Store
Taskreferences, cancel inviewDidDisappear— notdeinit; start work that should run while the screen is visible in an appearance callback, so it resumes when the screen reappears - Check
Task.isCancelledbefore UI updates afterawait Task.detacheddoes NOT inherit actor isolation — explicitMainActor.runneeded for UI- Avoid
DispatchQueue.main.syncto reach the main thread (it blocks the caller and deadlocks when already on main) — useawait MainActor.run
UIKit–SwiftUI Interop — see references/uikit-swiftui-interop.md
- UIHostingController: full child VC containment (
addChild→addSubview→didMove), retain as stored property sizingOptions = .intrinsicContentSize(iOS 16+) for Auto Layout containers- UIViewRepresentable: set mutable state in
updateUIView, notmakeUIView; guard against update loops - UIHostingConfiguration (iOS 16+) for SwiftUI content in collection view cells
Image Loading — see references/image-loading.md
- Decoded bitmap size = width × height × 4 bytes (a 12MP photo = ~48MB RAM)
- Consider downsampling with ImageIO to the display pixel size instead of decoding the full bitmap and resizing
- iOS 15+: consider
byPreparingThumbnail(ofSize:)orbyPreparingForDisplay()for async decoding - Cell reuse: cancel Task in
prepareForReuse, clear image, verify identity on completion
Keyboard & Scroll — see references/keyboard-scroll.md
- Use
UIKeyboardLayoutGuide(iOS 15+) — pin content bottom toview.keyboardLayoutGuide.topAnchor - iPad floating/undocked keyboard: set
followsUndockedKeyboard = trueand attach the constraints withsetConstraints(_:activeWhenNearEdge:)/setConstraints(_:activeWhenAwayFrom:)— a single fixed constraint misplaces content when the keyboard floats - Prefer the layout guide over manual keyboard notification handling; keep notifications only as the fallback below iOS 15
Adaptive Layout & Accessibility — see references/adaptive-appearance.md
- Use
registerForTraitChanges(iOS 17+) instead of deprecatedtraitCollectionDidChange; when the deployment target is below iOS 17, gate the registration with#availableand keeptraitCollectionDidChangeas the fallback - Dynamic Type:
UIFont.preferredFont(forTextStyle:)+adjustsFontForContentSizeCategory = true - Dark mode: use semantic colors (
.label,.systemBackground); re-resolve CGColor on trait changes withresolvedColor(with: traitCollection).cgColor— outside layout/draw callbacks and trait-change handlers the current trait collection is not guaranteed - VoiceOver: set
accessibilityLabel,accessibilityTraits,accessibilityHinton custom views - Use
UIAccessibilityCustomActionfor complex list item actions
Modern APIs (iOS 18–26) — see references/modern-uikit-apis.md
- Observation tracking: opt in with
UIObservationTrackingEnabledon iOS 18+ (on by default in iOS 26);@Observableproperties read inlayoutSubviews,viewWillLayoutSubviews, orconfigurationUpdateHandlerre-run that method when they change - Never write to an observed property inside a tracked method — it re-triggers the same method (update storm)
- iOS 26+: put content and styling in
updateProperties(), keep geometry inlayoutSubviews() - iOS 26+:
.flushUpdatesanimation option replaces the manuallayoutIfNeeded()steps UIScenelifecycle: iOS 26 only logs a warning; it becomes required when building with the SDK of the release after iOS 26- Liquid Glass (iOS 26+): standard bars adopt it automatically; gate
UIGlassEffectwith#availableand fall back toUIBlurEffect
Quick Reference — Deprecated → Modern APIs
| Deprecated / Legacy | Modern Replacement | Since |
|---|---|---|
traitCollectionDidChange | registerForTraitChanges(_:handler:) | iOS 17 |
| Keyboard notifications | UIKeyboardLayoutGuide | iOS 15 |
cell.textLabel / detailTextLabel | UIListContentConfiguration | iOS 14 |
register + string dequeue | UICollectionView.CellRegistration | iOS 14 |
reloadItems on snapshot | reconfigureItems | iOS 15 |
barTintColor / isTranslucent | UINavigationBarAppearance (4 slots) | iOS 13 |
UICollectionViewFlowLayout (complex) | UICollectionViewCompositionalLayout | iOS 13 |
Manual layoutIfNeeded() in animations | .flushUpdates option | iOS 26 |
| Legacy app lifecycle | UIScene + SceneDelegate | iOS 13; required with the SDK after iOS 26 |
ObservableObject + manual invalidation | @Observable + UIObservationTrackingEnabled | iOS 18 |
Review Checklist
One gate per domain (details in the matching Core Guideline above). Items before Optional are correctness gates; items after Optional are performance or modernization suggestions — raise them, but do not fail a review on them.
- Lifecycle — no geometry in
viewDidLoad(useviewIsAppearing); overrides callsuper(except aloadViewthat builds the view); child VC =addChild → addSubview → didMove;deinitconfirms dealloc - Auto Layout —
translatesAutoresizingMaskIntoConstraints = falseon views you constrain; no priority change to/from.requiredat runtime; nosetNeedsLayout()insidelayoutSubviews(infinite loop). Optional: batch withNSLayoutConstraint.activate([]); no churn (toggleisActive/.constant) - Collection views — diffable + stable identifiers; no duplicate snapshot IDs (
BUG_IN_CLIENTcrash); registration not created inside the cell provider. Optional:reconfigureItemsinstead ofreloadItems;CellRegistrationinstead of string dequeue - Navigation — all 4 appearance slots; on
navigationItemnotnavigationBar; concurrent-transition guard - Animation — API fits use case; constraint animation flush → update → animate;
CAAnimationsets model value first - Memory —
[weak self]in stored or long-lived escaping closures;Tasks cancelled inviewDidDisappear; timers/display links/tasks started in an appearance callback when stopped on disappearance; delegatesweak; no strong-self recapture in nested closures - Concurrency —
Task.isCancelledchecked afterawait; noDispatchQueue.main.synchop to main. Optional: no redundant@MainActoron VC subclasses - Images — cell load cancels in
prepareForReuse+ verifies identity. Optional: downsampled to display size;NSCachecost by decoded bytes - Interop —
UIHostingControllerretained + full containment;updateUIViewguards update loops - Keyboard — content follows the keyboard correctly; undocked tracking uses
setConstraints(_:activeWhen…). Optional:UIKeyboardLayoutGuideinstead of notifications (iOS 15+) - Adaptive/A11y — trait changes handled (
registerForTraitChangeson iOS 17+,traitCollectionDidChangefallback below); Dynamic Type; CGColor re-resolved withresolvedColor(with:);accessibilityLabel/Traitson custom views - Modern APIs — every API newer than the deployment target is behind
#availablewith a fallback; no writes to observed properties inside tracked methods. Optional:UIScenelifecycle;UIObservationTrackingEnabled
References
references/view-controller-lifecycle.md— Lifecycle ordering, viewIsAppearing, child VC containmentreferences/auto-layout.md— Batch activation, constraint churn, priority, animation, debuggingreferences/modern-collection-views.md— Diffable data sources, compositional layout, CellRegistrationreferences/cell-configuration.md— UIContentConfiguration, UIBackgroundConfiguration, configurationUpdateHandlerreferences/list-performance.md— Prefetching, cell reuse, reconfigureItems, scroll performancereferences/navigation-patterns.md— Bar appearance, concurrent transitions, large titles, deep linksreferences/animation-patterns.md— UIView.animate, UIViewPropertyAnimator, CAAnimation, springsreferences/memory-management.md— Retain cycles, [weak self], Timer/CADisplayLink/nested closure trapsreferences/concurrency-main-thread.md— @MainActor, Task lifecycle, Swift 6, GCD migrationreferences/uikit-swiftui-interop.md— UIHostingController, UIViewRepresentable, sizing, state bridgingreferences/image-loading.md— Downsampling, decoded bitmap math, cell reuse race conditionreferences/keyboard-scroll.md— UIKeyboardLayoutGuide, scroll view insets, iPad floating keyboardreferences/adaptive-appearance.md— Trait changes, Dynamic Type, dark mode, VoiceOver, accessibilityreferences/modern-uikit-apis.md— Observation framework, updateProperties(), .flushUpdates, UIScene, Liquid Glass
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/ivan-magda/uikit-expert-skill/uikit-expert">View uikit-expert on skillZs</a>