Pick the fix
TextField("Name", text: $profile.name) doesn't compile because profile is a plain property. Which fix?
@Observable final class Profile { var name = "" }
struct EditProfile: View {
var profile: Profile
var body: some View {
TextField("Name", text: $profile.name)
}
}Hint 1 of 2
Who owns profile?
Hint 2 of 2
Which wrapper is made for Observation?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A @Bindable var profile: Profile
Correct. @Bindable provides bindings to an @Observable object you were handed.
Why not the others?
- B
@State var profile: Profile. The child would take a copy of the reference as its own state and ignore later values from the parent. - C
@Binding var profile: Profile. That expects a Binding<Profile> from the parent, which isn't what you have. - D
@ObservedObject var profile: Profile. That needs ObservableObject; an @Observable class doesn't conform.