Agent skill · software engineering · dpearson2699
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.
Why this skill is useful
Provides specific patterns and code examples for integrating UIKit with SwiftUI that the AI wouldn't reliably generate on its own.
What it needs
About 9k tokens when loaded. Last updated 2026-07-31. 973 stars on the source repository.
What this skill does
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 for complete wrapping recipes and references/hosting-migration.md for UIKit-to-SwiftUI migration patterns. Contents UIViewRepresentable Protocol UIViewControllerRepresentable Protocol The Coordinator Pattern UIHostingController Sizing and Layout State Synchronization Patterns UIKit Automatic Observation Tracking Sendable Considerations Common Mistakes Review Checklist References UIViewRepresentable Protocol Use UIViewRepresentable to wrap any UIView subclass for use in SwiftUI. Required Methods Lifecycle Timing Method When Called Purpose -------- ----------- --------- makeCoordinator() Before makeUIView. Once per representable lifetime. Create the delegate/datasource reference type. makeUIView(context:) Once, when the representable enters the view tree. Allocate and configure the UIKit view. updateUIView(:context:) Immediately after makeUIView, then on every relevant state change. Push SwiftUI state into the UIKit view. dismantleUIView(:coordinator:) When the representable is removed from the view tree. Clean up observers, timers, subscriptions. sizeThatFits(:uiView:context:) During layout, when SwiftUI needs the view's ideal size. iOS 16+. Return a custom size proposal. Why updateUIView is the most important method: SwiftUI calls it every time any @Binding, @State, @Environment, or @Observable property read by the representable changes. All state synchronization from SwiftUI to UIKit happens here. If you skip a property, the UIKit view will fall out of sync. Optional: dismantleUIView Optional: sizeThatFits (iOS 16+) UIViewControllerRepresentable Protocol Use UIViewControllerRepresentable to wrap a UIViewController subclass -- typically for system pickers, document scanners, mail compose, or any controller that presents modally. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills dpearson2699/swiftui-uikit-interop