swiftui-uikit-interop
Installation
SKILL.md
SwiftUI ⇄ UIKit Interop
This skill covers the boundary between SwiftUI and UIKit — embedding one inside the other and passing data across. It does not cover pure-SwiftUI view design (use swiftui-expert) or the app's dependency graph (use ios-architecture-expert).
Agent Behavior Contract
When this skill is active, follow these rules strictly:
- This skill is only about the boundary. Pure SwiftUI view code → defer to
swiftui-expert; app architecture / composition root / DI → defer toios-architecture-expert. - Wrap UIKit in SwiftUI with a representable —
UIViewRepresentablefor a view,UIViewControllerRepresentablefor a view controller. Never new up a UIKit view directly inside a SwiftUIbody. - Route all UIKit delegate / data-source / target-action callbacks through a
Coordinator(makeCoordinator()), never store mutable UIKit state on the representable struct. - Data flows one way per direction: SwiftUI state →
updateUIView/updateUIViewController; UIKit events →Coordinator→@Binding/closure. Don't mutate SwiftUI state synchronously from insideupdateUIView. - Embed SwiftUI in UIKit with
UIHostingController— and when embedding (not presenting), add it as a child view controller (addChild/didMove(toParent:)), not just itsview. - Use
UIHostingConfigurationfor SwiftUI in collection/table cells (iOS 16+) — one configuration per cell, not aUIHostingControllerper cell. - Keep hosting sizing correct — set
sizingOptions/ honorintrinsicContentSize/safeAreaRegionsso Auto Layout and self-sizing cells measure the SwiftUI content. - Gate version-specific APIs (
UIHostingConfigurationiOS 16,UIHostingController.sizingOptionsiOS 16, trait-bridged environment iOS 17,@UIApplicationDelegateAdaptorlifecycle) with#available/@available.