I am following this tutorial: https://www.hackingwithswift.com/books/ios-swiftui/building-a-basic-layout
However, that code won’t work and in fact means something quite different. If we add the parentheses after calculateBedtime it means “call calculateBedtime() and it will send back to the correct function to use when the button is tapped.” So, Swift would require that calculateBedtime() returns a closure to run.
By writing calculateBedtime rather than calculateBedtime() we’re telling Swift to run that method when the button is tapped, and nothing more; it won’t return anything that should then be run
Button(action: calculateBedtime()) {
Text("Calculate")
}
Button(action: calculateBedtime) {
Text("Calculate")
}
What is the difference between these two ? I couldnt understand Paul Hudson explanation very well.
Everytime I call a function i put ()
this time why i need to omit ()
?