Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active September 18, 2022 00:35
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 laevandus/e12f4bbec3e1caa0e39cfdbe9d9d5571 to your computer and use it in GitHub Desktop.
Save laevandus/e12f4bbec3e1caa0e39cfdbe9d9d5571 to your computer and use it in GitHub Desktop.
// Presenting the detail view using UIKit presentation methods
let hostingController = DetailView().embeddedInHostingController()
presentingViewController.present(hostingController, animated: true)
// The view which needs access to the view controller hosting it
struct DetailView: View {
@EnvironmentObject var hostingProvider: ViewControllerProvider
var body: some View {
VStack {
Text("Detail")
Button("Access View Controller") {
let viewController = hostingProvider.viewController
// … do something with the view controller
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment