Xcode 15 introduced a nice shortcut that converts functions with many parameters on a single line to a function that has any parameter on its own line.

Usage

The below function can be hard to read since all the arguments are on the same line.

To improve the readability we could move each argument on a separate line manually, but that is pretty tedious, especially if the codebase is not formatted at all.

Fortunately, now Xcode 15 has a handy formatting feature that enables us to do it automatically.

func function(with: String, many: String, parameters: [String], that: Int, can: String, beHard: String, toRead: Int) {

}

To format the function on multiple lines:

  1. Right-click on a parameter or select the entire function and hit right-click.
  2. Choose Refactor
  3. Then select Format to Multiple Lines

    The result is the following, a nicely formatted function with each parameter on a new line.

func function(

    with: String,

    many: String,

    parameters: [String],

    that: Int,

    can: String,

    beHard: String,

    toRead: Int

) {

}

Conclusion

This is a nice addition that can speed up the workflow.

Unfortunately there isn’t a shortcut for this option and there is no possibility to add one from the settings.

But it could be really useful to be able to add one, since this is a feature that could

be used quite frequently.

What are you thoughts about this? Tweet me @franceleonidev and share your opinion.

Source link