Format Functions to Multiple Lines in Xcode 15
Make you code easier to read formatting your functions to multiple lines with the option 'Format to Multiple Lines' in Xcode 15.
• 2 min read
Availability
Xcode 15
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:
- Right-click on a parameter or select the entire function and hit right-click.
- Choose
Refactor
- 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.
If you have any question about this article, feel free to email me or tweet me @franceleonidev and share your opinion.
Thank you for reading and see you in the next article!
Share this article