What problem does it solve?
Integrating legacy or platform-only UIKit components into modern SwiftUI apps is error-prone and full of lifecycle, sizing, and delegate synchronization pitfalls; this Skill documents patterns to reliably wrap views and view controllers, embed SwiftUI inside UIKit, and keep state consistent across the boundary.
Core Features & Use Cases
- UIViewRepresentable & UIViewControllerRepresentable: Clear lifecycle rules for creating, updating, sizing, and dismantling UIKit hosts in SwiftUI.
- Coordinator Pattern & Delegation: Best practices for wiring delegates, avoiding retain cycles, and routing results back to SwiftUI via bindings or closures.
- UIHostingController Embedding & Sizing: Correct child containment, sizingOptions usage, and strategies for Auto Layout, intrinsic sizing, and collection/table view hosting.
- State Synchronization & Concurrency: Two-way @Binding sync patterns, environment bridging, and MainActor/Sendable considerations for modern Swift concurrency.
- Use Cases: Camera previews, map views, document scanners, mail/message composers, PDF rendering, legacy screen migrations, and collection/table view SwiftUI cell hosting.
Quick Start
Wrap your UIKit view or controller using UIViewRepresentable or UIViewControllerRepresentable, set up a Coordinator to forward delegate callbacks into @Binding properties, and embed or present the resulting wrapper where you need it.