AGENTS.ios.md — iOS apps: SwiftUI / UIKit / Xcode
Additive to ../AGENTS.md and AGENTS.swift.md. iOS app rules only.
Build and check
swiftformat --lint . && swiftlint --strict
xcodebuild test -scheme App -destination 'platform=iOS Simulator,name=iPhone 16'
SwiftUI rules
- Views are small and take their data in. No networking in a
body. - New design system components need a
#Previewand must use tokens from the shared style layer, not literal colors or spacings. @StateObjectat ownership,@ObservedObjectwhen passed in. Getting this backwards causes the bugs nobody can reproduce.- For
@Observabletypes (iOS 17+):@Stateat ownership, a plain property when passed in,@Bindablewhen the child needs bindings. - Async work tied to a view’s lifetime goes in
.task {}, which cancels on disappear. NotonAppear { Task { … } }.
UIKit rules
- A view controller owns layout and view lifecycle. Networking, persistence and business logic live in a view model or service it is handed.
- No new storyboards. New screens are programmatic UIKit, or SwiftUI hosted in a
UIHostingController. Existing storyboards stay until their screen is rebuilt. - Auto Layout via
NSLayoutConstraint.activate, withtranslatesAutoresizingMaskIntoConstraints = false. No frame math inlayoutSubviewswithout a measured reason. - Escaping closures that can outlive the controller capture
[weak self]. Delegates areweak. - New table and collection views use diffable data sources, not
reloadData()plus index bookkeeping. - Keep the bridges thin:
UIHostingControllerfor SwiftUI in UIKit,UIViewRepresentable/UIViewControllerRepresentablefor UIKit in SwiftUI.
Xcode project
- Build settings live in
.xcconfigfiles, not the project editor..xcconfigfiles are Kitchen. - Swift rules, dependencies and testing are in
AGENTS.swift.md.
Anti-patterns seen in this repo
- Massive view files (>300 lines) that should be decomposed.
- Massive view controllers:
URLSessionor persistence calls in aUIViewController.