Support use of an optional label for the first trailing closure

I would prefer the former example yes. If it fits my line width, which is 80, then I'd use that style. The latter example is totally busted in terms of readability and proper code indentation.

So I would pick one the following styles:

Button(action: self.buttonTapped) 
  label: {
    Text("My button")
  }
  .modifier()

// this one is strange though.
Button
  .init(action: self.buttonTapped) 
  label: {
    Text("My button")
  }
  .modifier()

Button
  .init(action: self.buttonTapped) {
    Text("My button")
  }
  .modifier()

// preferred because of the clarity provided
// by the labels
Button
  .init(
    action: self.buttonTapped,
    label: {
      Text("My button")
    }
  ) 
  .modifier()

Do we have an estimate about when this could be moved into the release process again ?

6 Likes

The support of an optional label for the first trailing closure would make the "incorrect argument label" fix-its more consistent and simple. As an example:

func filter(by: () -> (), until: () -> ()) {}

// error: Incorrect argument labels in call (have '_:by:', expected 'by:until:')
// fix-it: Replace '{} by' with 'by: {} until'
filter {} by: {}

The proposed fix-it suggests

filter by: {} until: {}

which would be valid under this proposed pitch.