swiftui-uikit-interop
Bridges UIKit and SwiftUI with UIViewRepresentable, UIViewControllerRepresentable, UIHostingController, UIHostingConfiguration, coordinator delegates, and UIKit automatic observation tracking for shared @Observable state. Use when wrapping UIKit-only or third-party UIKit views/controllers in SwiftUI, embedding SwiftUI in UIKit, integrating mail/share/document/PDF/text-view surfaces, or migrating UIKit apps to SwiftUI incrementally.
npx skills add dpearson2699/swift-ios-skills --skill swiftui-uikit-interop --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Bridges UIKit and SwiftUI in both directions: wrap UIKit views and controllers, embed SwiftUI in UIKit screens, and synchronize state without duplicating lifecycle ownership.
How it works
- Provides wrappers using UIViewRepresentable and UIViewControllerRepresentable to expose UIKit views and view controllers to SwiftUI.
- Uses a Coordinator class to handle UIKit delegation and callbacks, routing results back to SwiftUI via @Binding or closures.
- Demonstrates embedding SwiftUI content inside UIKit with UIHostingController, including the three-step containment sequence (addChild, add view, didMove).
- Shows how to set up UIHostingConfiguration for cell content in collection/table views and how to manage sizing via sizingOptions and intrinsic content size.
- Explains state synchronization patterns: two-way with @Binding, one-way events with closures, and environment access within representable methods.
- Details UIKit Automatic Observation Tracking considerations and Sendable guidance for coordinators.
When to use it
Use when wrapping UIKit-only or third-party UIKit views/controllers in SwiftUI, embedding SwiftUI in UIKit, integrating mail/share/document/PDF/text-view surfaces, or migrating UIKit apps to SwiftUI incrementally.
What it can touch
- Uses UIViewRepresentable, UIViewControllerRepresentable, UIHostingController, UIHostingConfiguration, and a Coordinator class to bridge between SwiftUI and UIKit.
- Demonstrates interaction with @Binding, closures, and @Observable state tracking.
Caveats
- Advises on proper lifecycle handling (e.g., set delegates in makeUIView/makeUIViewController, guard against update loops).
- Notes platform/version constraints (iOS 16+ sizeThatFits and UIHostingConfiguration; iOS 26+ updateProperties; iOS 18 Info.plist requirement for UIKit tracking; iOS 17 limitations on @Observable).
- Discusses concurrency guidance for coordinators (e.g., @MainActor).
# SwiftUI-UIKit Interop Bridge UIKit and SwiftUI in both directions: wrap UIKit views and controllers, embed SwiftUI in UIKit screens, and synchronize state without duplicating lifecycle ownership. See [references/representable-recipes.md](references/representable-recipes.md) for complete wrapping recipes and [references/hosting-migration.md](references/hosting-migration.md) for UIKit-to-SwiftUI migration patterns. ## Contents - [UIViewRepresentable Protocol](#uiviewrepresentable-protocol) - [UIViewControllerRepresentable Protocol](#uiviewcontrollerrepresentable-protocol) - [The Coordinator Pattern](#the-coordinator-pattern) - [UIHostingController](#uihostingcontroller) - [Sizing and Layout](#sizing-and-layout) - [State Synchronization Patterns](#state-synchronization-patterns) - [UIKit Automatic Observation Tracking](#uikit-automatic-observation-tracking) - [Sendable Considerations](#sendable-considerations) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## UIViewRepresentable Protocol Use `UIViewRepresentable` to wrap any `UIView` subclass for use in SwiftUI. ### Required Methods ```swift struct WrappedTextView: UIViewRep
- Contents
- UIViewRepresentable Protocol
- Required Methods
- Lifecycle Timing
- Optional: dismantleUIView
- Optional: sizeThatFits (iOS 16+)
- UIViewControllerRepresentable Protocol
- Handling Results from Presented Controllers
- The Coordinator Pattern
- Why Coordinators Exist
- Structure
- Key Rules
- UIHostingController
- Basic Embedding
What does the swiftui-uikit-interop skill do?
Bridges UIKit and SwiftUI with UIViewRepresentable, UIViewControllerRepresentable, UIHostingController, UIHostingConfiguration, coordinator delegates, and UIKit automatic observation tracking for shared @Observable state. Use when wrapping UIKit-only or third-party UIKit views/controllers in SwiftUI, embedding SwiftUI in UIKit, integrating mail/share/document/PDF/text-view surfaces, or migrating UIKit apps to SwiftUI incrementally.
How do I install it?
Run `npx skills add dpearson2699/swift-ios-skills --skill swiftui-uikit-interop --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From dpearson2699/swift-ios-skills, a repository with 963 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.