SwiftUI Fundamentals

Feb 28 2023 Swift 5.7, macOS Venture 13.1, Xcode 14.2

Part 2: Navigation & Data Flow

18. Environment

Episode complete

Play next episode

Next
About this episode
See versions
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 17. Challenge: StateObject & ObservableObject Next episode: 19. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Pro subscription. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

This video Environment was last updated on Feb 28 2023

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

What if you have some data that lots of parts of your app depend on, like your user model?

MovieList()
  .environmentObject(UserStore())
@EnvironmentObject var userStore: UserStore
leading:
  NavigationLink(destination: UserView(❌userStore: userStore❌))
@EnvironmentObject var userStore: UserStore
struct UserView_Previews: PreviewProvider {
  static var previews: some View {
    UserView()
      .environmentObject(UserStore())
  }
}
@EnvironmentObject var userStore: UserStore
.onAppear { genre = userStore.currentUserInfo.favoriteGenre }
static var previews: some View {
  MovieList(movieStore: MovieStore())
    .environmentObject(UserStore())
}
@Environment(\.dismiss) var dismiss
dismiss()