Skip to content

Instantly share code, notes, and snippets.

@karthironald
Created May 7, 2020 03:23
Show Gist options
  • Save karthironald/e7d343a63044140b2c8bd444dfa1c4b7 to your computer and use it in GitHub Desktop.
Save karthironald/e7d343a63044140b2c8bd444dfa1c4b7 to your computer and use it in GitHub Desktop.
class Order: ObservableObject {
@Published var items = [MenuItem]()
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var order = Order()
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
...
let contentView = AppView().environmentObject(order) // Setting order in environment of AppView() which is TabView in my case.
...
}
}
struct CheckoutView: View { // CheckoutView is one of the tab in TabView. Child view of AppView. So CheckoutView can access saved order from parent's environment
@EnvironmentObject var order: Order
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment