SwiftUI Favorite Button Constructor

One thing I don’t like about Swift and SwiftUI is overloaded constructors, there’s at least 3 ways to create a button.

What’s your favorite way?

Compact constructor.

Button( "Label" ) {
 // code goes here
}

or

Button( "Label", systemImage: "plus" ) { // code goes here }

Action first then label

Button( action: { // code goes here } ) {
 HStack{ 
  Image( systemName: "plus" )
  Text( "Label" )
 }
}

Another way of action first then label.

Button {
 // code goes here
} label: {
 Text( "Label" )
}

The last two allow for far more control over the button label, including images that are not SF Symbols, but I think I prefer the compact version.

It depends on what you want to achieve. There is a great choice of options but we need to keep that stuff in our brain…
I prefer a somewhat overwhelming number of options to a bare-bones system where I get stuck if something beyond very basic UI functionality is needed.

Sometimes compact, often the 3. example. For a simple ‘Quit’, I’d use of the compact one…

Yes, the constructors are not always ‘best’

Thankfully the auto complete in Xcode and the Swift language make having multiple constructors much easier than it was with Xojo.