Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mhijack/2478619dc83cc2eb439d9cc808a32b9a to your computer and use it in GitHub Desktop.
Save mhijack/2478619dc83cc2eb439d9cc808a32b9a to your computer and use it in GitHub Desktop.
struct EnvironmentContainerView: View {
@State var bookStore = BookStore()
var body: some View {
EnvChildView()
.environmentObject(bookStore) // <- `EnvironmentObject` as a view modifier
}
}
struct EnvChildView: View {
var body: some View {
EnvChildChildView()
}
}
struct EnvChildChildView: View {
@EnvironmentObject var bookStore: BookStore // <- `EnvironmentObject` as a property wrapper
var body: some View {
Text(bookStore.books[0].name) // "The Great Influenza"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment