Skip to content

Instantly share code, notes, and snippets.

@stormychel
Created December 6, 2022 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormychel/83c4611639b29da2e91749f9b8e018bb to your computer and use it in GitHub Desktop.
Save stormychel/83c4611639b29da2e91749f9b8e018bb to your computer and use it in GitHub Desktop.
Return UIHostingController for a SwiftUI View, ready to use with UIKit.
extension AnyView {
/// Return UIHostingController for a SwiftUI View.
/// - Usage: let vc = AnyView( YourSwiftUIViewHere() ).asUIHostingController()
/// - Created by Michel Storms.
/// - Returns: UIHostingController ready to use with UIKit.
func asUIHostingController() -> UIHostingController<AnyView> {
return UIHostingController(rootView: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment