[Chapter 15: Grids] AwardsView body indirectly uses `flightNavigation `

Hello @bmorefield ,

Thank you for the great article for Grids. I am wandering about content view refresh for AwardsView when we indirectly use flightNavigation via computed properties:

  @EnvironmentObject var flightNavigation: AppEnvironment

  var awardArray: [AwardInformation] {
    flightNavigation.awardList
  }
    var awardColumns: [GridItem] {
     [GridItem(.adaptive(minimum: 150, maximum: 170))]
   }
    
    var activeAwards: [AwardInformation] {
      awardArray.filter { $0.awarded }
    }
    var inactiveAwards: [AwardInformation] {
      awardArray.filter { !$0.awarded }
    }

How does SwiftUI knows it needs to update AwardsView’s body since it don’t reference flightNavigation directly?

Thanks,
Dzmitry.

@Audrey , maybe you could support?
Basically the question “is it safe to do it this way, indirect usage of flightNavigation to make sure body will gets updated every time”

Thanks,
Dzmitry.

hi Dzmitry! flightNavigation is an EnvironmentObject, so AwardsView redraws itself whenever it observes a change in flightNavigation. It’s like an ObservedObject, but doesn’t need to be passed as a parameter.

Environment objects are explained in 9.2 Sharing the Environment

1 Like