swiftui-uikit-interop

Bridge SwiftUI and UIKit using representable wrappers and hosting controllers.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/KumarAdi8/AgentKit --skill swiftui-uikit-interop-kumaradi8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-uikit-interop
Source: https://github.com/KumarAdi8/AgentKit/tree/main/skills/swiftui-uikit-interop
Command: npx skills add https://github.com/KumarAdi8/AgentKit --skill swiftui-uikit-interop-kumaradi8

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Integrating UIKit components and third-party UIKit SDKs into a SwiftUI app (and embedding SwiftUI into UIKit) is error-prone due to lifecycle differences, delegate patterns, sizing mismatches, and concurrency boundaries. This Skill provides patterns, recipes, and checklist items to reliably wrap UIView and UIViewController classes, host SwiftUI inside UIKit, and keep state synchronized across the boundary so UI, accessibility, and presentation semantics remain correct.

Core Features & Use Cases

  • Wrap UIKit views with UIViewRepresentable and view controllers with UIViewControllerRepresentable for use in SwiftUI.
  • Implement the Coordinator pattern to route delegate callbacks and avoid retain cycles; use dismantle hooks to clean up observers and timers.
  • Embed SwiftUI in UIKit using UIHostingController and UIHostingConfiguration (iOS 16+) with proper containment, Auto Layout, and sizing strategies.
  • State synchronization patterns: @Binding two-way sync, closures for one-way events, environment bridging, and approaches for @Observable/Combine interop.
  • Concurrency and safety guidance for main-actor isolation and Sendable considerations when coordinators implement UIKit delegates.
  • Use cases: camera previews, map views, document scanners, mail/message composers, PDF viewers, rich text editors, collection/table cells with SwiftUI content, and incremental migration of large UIKit apps.

Quick Start

Wrap the UIKit view or view controller with UIViewRepresentable or UIViewControllerRepresentable, create a Coordinator to handle delegate callbacks, implement make/update/dismantle methods, and embed with UIHostingController when hosting SwiftUI inside UIKit.

Frequently Asked Questions about swiftui-uikit-interop

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wrap a UIKit view in SwiftUI using UIViewRepresentable?

To wrap a UIKit view in SwiftUI, implement UIViewRepresentable by creating a Coordinator for delegate callbacks and adding makeUIView, updateUIView, and dismantleUIView methods to handle lifecycle and state synchronization.

How do I embed SwiftUI views inside a UIKit app?

Embed SwiftUI views inside UIKit using UIHostingController with proper view controller containment, Auto Layout constraints, and sizing strategies to ensure correct presentation semantics and state synchronization across the boundary.

What is the best way to migrate a UIKit app to SwiftUI incrementally?

Incremental migration from UIKit to SwiftUI involves wrapping specific UIKit views with UIViewRepresentable or UIViewControllerRepresentable and hosting new SwiftUI content with UIHostingController while maintaining state synchronization through bindings and closures.

How does the Coordinator pattern work when bridging SwiftUI and UIKit?

The Coordinator pattern in SwiftUI and UIKit interop routes UIKit delegate callbacks back to SwiftUI, manages state updates safely, and avoids retain cycles when handling lifecycle events and main-actor concurrency boundaries.

Why does my UIHostingController sizing not match the SwiftUI content?

UIHostingController sizing mismatches occur when Auto Layout constraints and sizing strategies are not properly configured; correct containment and sizing logic must be applied to ensure the hosted SwiftUI content fits the UIKit layout boundaries.

Can I integrate camera previews and map views from UIKit into SwiftUI?

Yes, camera previews, map views, document scanners, and mail composers can be integrated into SwiftUI by wrapping their respective UIKit views and view controllers with UIViewRepresentable and UIViewControllerRepresentable.