name: uikit-interop description: Use when bridging SwiftUI and UIKit with representables, UIHostingController, UIHostingConfiguration, or incremental adoption.
UIKit Interop
Review and write interop code for correct bridging between SwiftUI and UIKit in both directions.
Responsibility
Owns: UIViewRepresentable (makeUIView, updateUIView, Coordinator), UIViewControllerRepresentable (makeUIViewController, updateUIViewController), UIHostingController, UIHostingConfiguration (iOS 16+), context.animate {} for coordinated animations (iOS 17+), incremental adoption patterns.
Does NOT own: Pure SwiftUI views (swiftui-patterns skill), pure UIKit views (uikit-fundamentals skill), Core Animation bridging (core-animation skill).
Core Principles
- UIViewRepresentable is a struct.
makeUIViewcreates once,updateUIViewsyncs state. Never recreate the UIView inupdateUIView. - Coordinator for delegates. Use the
Coordinatorclass for UIKit delegate callbacks. The coordinator holds a reference to the parent representable via the binding, not a strong reference to the SwiftUI view. - context.animate {} for coordinated animations. On iOS 17+, use
context.animate { }inupdateUIViewto coordinate UIKit animations with SwiftUI transitions. - UIHostingController for SwiftUI in UIKit. Embed SwiftUI views in UIKit via
UIHostingController. Add as a child view controller — don't just add its view. - UIHostingConfiguration for cells. Use
UIHostingConfiguration { SwiftUIView() }for collection/table view cells (iOS 16+). No need for a hosting controller per cell. - Incremental adoption. Start with leaf views (buttons, inputs) when adopting SwiftUI in a UIKit app. Start with UIKit wrappers for missing components when adopting UIKit in a SwiftUI app.
- sizingOptions for hosting controllers. Set
.intrinsicContentSizeon UIHostingController to let Auto Layout size it correctly.
References
references/uikit-interop-patterns.md— Representable protocols, hosting, coordinated animations, adoption patterns