-
-
Save laevandus/8c2b97163af31b087e15ae9e032aef14 to your computer and use it in GitHub Desktop.
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 View { | |
func embeddedInHostingController() -> UIHostingController<some View> { | |
let provider = ViewControllerProvider() | |
let hostingAccessingView = environmentObject(provider) | |
let hostingController = UIHostingController(rootView: hostingAccessingView) | |
provider.viewController = hostingController | |
return hostingController | |
} | |
} | |
final class ViewControllerProvider: ObservableObject { | |
fileprivate(set) weak var viewController: UIViewController? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment