Reputation: 1325
I have got a modal sheet built with SwiftUI
but the rest of my app is UIKit
. I want to display modal when user taps a button in UIKit
. How do I implement this?
Upvotes: 4
Views: 3114
Reputation: 1325
Create a UIHostingController
with your SwiftUI view set as its rootView
, and present that as normal.
let hostingController = UIHostingController(rootView: MyModalView())
self.present(hostingController, animated: true, completion: nil)
Upvotes: 8
Reputation: 4719
You can load your SwiftUI view using UIHostingController(rootView: YourSwiftUIView())
and present it in your UIKit
Upvotes: 3