Predict the output
profile.name changes. Which view bodies re-run?
@Observable final class Profile {
var name = "Ana"
var avatarURL: URL?
}
struct NameView: View {
let profile: Profile
var body: some View { Text(profile.name) }
}
struct AvatarView: View {
let profile: Profile
var body: some View { AsyncImage(url: profile.avatarURL) }
}Hint 1 of 1
Which body reads name?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B Only NameView
Correct. Only NameView's body read name.
Why not the others?
- A Both NameView and AvatarView. That is ObservableObject behaviour. Observation tracks per property.
- C Neither, because
letproperties aren't observed. Observation tracks reads in body regardless of wrappers. - D Every view in the app. Only views that read the changed property update.