Created
December 6, 2022 22:19
-
-
Save stormychel/83c4611639b29da2e91749f9b8e018bb to your computer and use it in GitHub Desktop.
Return UIHostingController for a SwiftUI View, ready to use with UIKit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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