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.
91%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
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.
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:
viewDidLoad, geometry in viewIsAppearing[weak self], Task cancellation), concurrency (@MainActor)#available and a fallbackreferences/view-controller-lifecycle.mdviewDidLoad for one-time setup: subviews, constraints, delegates — NOT geometryviewIsAppearing (back-deployed iOS 13+) for geometry-dependent work, trait-based layout, scroll-to-itemviewDidLayoutSubviews fires multiple times — use only for lightweight layer frame adjustmentsviewWillAppear is limited to transition coordinator animations and balanced notification registrationsuper in lifecycle overrides — except a loadView override that builds the view hierarchy itself, which must not call superaddChild → addSubview → didMove(toParent:) — in that exact orderdeinit logging during developmentreferences/auto-layout.mdtranslatesAutoresizingMaskIntoConstraints = false on views you position with your own constraints — not on views UIKit positions for you (a pushed or presented controller's root view, a cell's contentView)NSLayoutConstraint.activate([]) over setting .isActive = true one constraint at a time (one batch for the layout engine)isActive or modify .constant — avoid removing and recreating them.required (1000) at runtime — use 999layoutIfNeeded() inside animation block on superview.flushUpdates option to simplify constraint animationconstraint.identifier on key constraints so Unable to simultaneously satisfy constraints logs are readablelet 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),
])references/modern-collection-views.md, references/cell-configuration.md, references/list-performance.mdUICollectionViewDiffableDataSource with stable identifiers (UUID/database ID, not full model structs)reconfigureItems (iOS 15+) for content updates, reloadItems only when cell type changes; with observation tracking enabled (iOS 18+ opt-in, default on iOS 26), @Observable reads in configurationUpdateHandler refresh the cell without a snapshotapplySnapshotUsingReloadData for initial population (bypasses diffing)UICollectionViewCompositionalLayout for any non-trivial layoutUICollectionView.CellRegistration — no string identifiers, no manual castingUIContentConfiguration for cell content and UIBackgroundConfiguration for cell backgroundsconfigurationUpdateHandler for 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)references/navigation-patterns.mdUINavigationBarAppearance slots (standard, scrollEdge, compact, compactScrollEdge)navigationItem (per-VC) in viewDidLoad, not on navigationBar in viewWillAppearsetViewControllers(_:animated:) for deep links — not sequential push callstransitionCoordinator before push/popprefersLargeTitles once on the bar; use largeTitleDisplayMode per VCreferences/animation-patterns.mdUIView.animate — simple one-shot animations; check finished in completionUIViewPropertyAnimator — gesture-driven, interruptible; respect state machine (inactive → active → stopped)CABasicAnimation — layer-only properties (cornerRadius, shadow, 3D transforms); set model value firstUIView.animate(springDuration:bounce:) aligns with SwiftUIlayoutIfNeeded() on superviewreferences/memory-management.md[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 (the self: Self parameter of a registerForTraitChanges handler)[weak self]; start it in an appearance callback (viewIsAppearing) and invalidate in viewWillDisappear, so it restarts when the screen reappears[weak self] in closure, remove observer in deinit[weak self] in stored inner closuresweak var delegate: SomeDelegate? with AnyObject constraintdeinit — if never called, a retain cycle existsreferences/concurrency-main-thread.mdUIViewController is @MainActor — all subclass methods are implicitly main-actorTask references, cancel in viewDidDisappear — not deinit; start work that should run while the screen is visible in an appearance callback, so it resumes when the screen reappearsTask.isCancelled before UI updates after awaitTask.detached does NOT inherit actor isolation — explicit MainActor.run needed for UIDispatchQueue.main.sync to reach the main thread (it blocks the caller and deadlocks when already on main) — use await MainActor.runreferences/uikit-swiftui-interop.mdaddChild → addSubview → didMove), retain as stored propertysizingOptions = .intrinsicContentSize (iOS 16+) for Auto Layout containersupdateUIView, not makeUIView; guard against update loopsreferences/image-loading.mdbyPreparingThumbnail(ofSize:) or byPreparingForDisplay() for async decodingprepareForReuse, clear image, verify identity on completionreferences/keyboard-scroll.mdUIKeyboardLayoutGuide (iOS 15+) — pin content bottom to view.keyboardLayoutGuide.topAnchorfollowsUndockedKeyboard = true and attach the constraints with setConstraints(_:activeWhenNearEdge:) / setConstraints(_:activeWhenAwayFrom:) — a single fixed constraint misplaces content when the keyboard floatsreferences/adaptive-appearance.mdregisterForTraitChanges (iOS 17+) instead of deprecated traitCollectionDidChange; when the deployment target is below iOS 17, gate the registration with #available and keep traitCollectionDidChange as the fallbackUIFont.preferredFont(forTextStyle:) + adjustsFontForContentSizeCategory = true.label, .systemBackground); re-resolve CGColor on trait changes with resolvedColor(with: traitCollection).cgColor — outside layout/draw callbacks and trait-change handlers the current trait collection is not guaranteedaccessibilityLabel, accessibilityTraits, accessibilityHint on custom viewsUIAccessibilityCustomAction for complex list item actionsreferences/modern-uikit-apis.mdUIObservationTrackingEnabled on iOS 18+ (on by default in iOS 26); @Observable properties read in layoutSubviews, viewWillLayoutSubviews, or configurationUpdateHandler re-run that method when they changeupdateProperties(), keep geometry in layoutSubviews().flushUpdates animation option replaces the manual layoutIfNeeded() stepsUIScene lifecycle: iOS 26 only logs a warning; it becomes required when building with the SDK of the release after iOS 26UIGlassEffect with #available and fall back to UIBlurEffect| 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 |
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.
viewDidLoad (use viewIsAppearing); overrides call super (except a loadView that builds the view); child VC = addChild → addSubview → didMove; deinit confirms dealloctranslatesAutoresizingMaskIntoConstraints = false on views you constrain; no priority change to/from .required at runtime; no setNeedsLayout() inside layoutSubviews (infinite loop). Optional: batch with NSLayoutConstraint.activate([]); no churn (toggle isActive/.constant)BUG_IN_CLIENT crash); registration not created inside the cell provider. Optional: reconfigureItems instead of reloadItems; CellRegistration instead of string dequeuenavigationItem not navigationBar; concurrent-transition guardCAAnimation sets model value first[weak self] in stored or long-lived escaping closures; Tasks cancelled in viewDidDisappear; timers/display links/tasks started in an appearance callback when stopped on disappearance; delegates weak; no strong-self recapture in nested closuresTask.isCancelled checked after await; no DispatchQueue.main.sync hop to main. Optional: no redundant @MainActor on VC subclassesprepareForReuse + verifies identity. Optional: downsampled to display size; NSCache cost by decoded bytesUIHostingController retained + full containment; updateUIView guards update loopssetConstraints(_:activeWhen…). Optional: UIKeyboardLayoutGuide instead of notifications (iOS 15+)registerForTraitChanges on iOS 17+, traitCollectionDidChange fallback below); Dynamic Type; CGColor re-resolved with resolvedColor(with:); accessibilityLabel/Traits on custom views#available with a fallback; no writes to observed properties inside tracked methods. Optional: UIScene lifecycle; UIObservationTrackingEnabledreferences/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