Created
June 13, 2021 00:16
-
-
Save mhijack/2478619dc83cc2eb439d9cc808a32b9a 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
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