Post

Replies

Boosts

Views

Created

SwiftUI view execution confusion, both buttons execute same code
I am fairly new to SwiftUI and am having trouble understanding why the following view / form executes the same code no matter what button is pushed. If I click the cancel button I get on the console. in cancel in save If I click the save button, I get the same thing. in cancel in save I know I am missing something fundamental, but can't sort it out. Any help would be appreciated. var body: some View { Form { TextField("Enter name", text: $personModel.modelName) HStack { Button("Cancel") { print("in cancel") presentationMode.wrappedValue.dismiss() } Spacer() Button("Save") { print("in save") personModel.save() presentationMode.wrappedValue.dismiss() } } } }
2
0
1.9k
Oct ’21