I have a UserService class with an optional user variable.
struct User: Codable {
var id, first_name, last_name, dob: String
}
class UserService : ObservableObject {
@Published var user: User?
}
I pass this object from a view to another view in NavigationLink.
NavigationLink(destination: EditProfileView(userService: userService).navigationBarBackButtonHidden(true), isActive: $editProfileScreenActive){
Text("")
}
In EditProfileView I was not able to use the properties of User in TextField. e.g.
TextField("first_name", text: $userService.user?.first_name)
I tried different approaches but was not able to pass first_name as a binding to TextField. I am getting different kinds of compilation errors.
Any suggestions how to fix this? (I am not an experienced swift programmer :) )