Post

Replies

Boosts

Views

Activity

Reply to Conditionals and Identity
The latter is preferred as it's one view with an inter modifier applied to it. The first example, the one with if/else branches, has two separate views (with different entities, one for each branch). Moreover, if the view DogTreatView in the first example also had its own state (via @State or @StateObject), then this state would reset every time you switch branches (a.k.a. the isExpired condition changes). Meanwhile, in the second example, the state would persist whenever isExpired changes, as in that case, the view is the same, just with a different opacity value
Jun ’21
Reply to How to fix the issue in the code shown at 21:40
You'll need to use an inert view modifier. Something along the lines of: var body: some View { CatRecorder() .carStyle(dayTime ? .nightTime : .noStyle) } This way SwiftUI knows that this is the same view where the style might change. With this declaration, the view identity is preserved, but its value (in this case the style value) might change over time
Jun ’21