I have a user data saved in UserDefaults, now I want to make an edit profile view and I want to use TextField to show current user data, but I get this error because I put the code inside the body Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols. I want to display all current user data inside the TextField, so they can see their data before make an edit. how to do that correctly?
MyCode
struct EditProfile: View {
@AppStorage(CurrentUserDefaults.EMAIL) var currentUserEmail: String?
@AppStorage(CurrentUserDefaults.USERNAME) var currentUserName: String?
@State var userName = ""
@State var userPhone = ""
@State var userAddress = ""
var body: some View {
username = currentUserName ?? "" //[Error] I want to display currentUserName on the textfield
NavigationView{
VStack{
TextField("Username", text: $userName)
}.navigationBarTitle("Edit Profile")
}.navigationViewStyle(StackNavigationViewStyle())
}
}