I find the "Button" in SwiftUI confusing

In tutorial I was watching someone created a button with SwiftUI in Xcode,
and it looked like something like this:

Button(action: {
print("something")
}) {
   Text("Send")
}

If I drag and drop "button" option in Xcode, it creates something like this:

Button("Send") {
print("something")
}

I find it confusing that you can kind of do it in 2 ways.
Is the first one used most of the time?

What you're seeing is not specific to Button, or even Swift itself. It's called overloading, and the official Swift documentation doesn't cover it, so it's hard for a beginner to learn.

Here are the two overloads you've posted:

4 Likes