CommentComment

I noticed something while reading Nezhyborets Oleksiiā€™s latest post on formatting code across multiple lines. He skipped over a new Xcode feature, but it caught my eye as I have been hoping Apple would add this for years!

New in Xcode 16ā€™s ā€œEditorā€ menu under ā€œStructureā€ youā€™ll find ā€œFormat File with swift-formatā€. šŸ˜ I couldnā€™t wait to try it, so I loaded an Xcode project, opened a file, and it worked flawlessly! I donā€™t have swift-format installed globally on my machine, so Xcode must now bundle a version of the tool. It turns out that itā€™s now part of the Swift 6.0 toolchain. Even better!

Why am I so excited about this, though? We have been able to run this tool for years.

Iā€™m excited because I care about formatting tools like this becoming trivial to use, and even one day for it to become default to run this tool every time you save a file. šŸ˜±

I wrote something on ā€œPrettierā€ a couple of years ago, and Iā€™d urge you to re-read it before you continue. Itā€™ll explain why I want this so much, and my feelings have only become stronger about it since then.

Exposing swift-format in Xcode is step one to that dream of the Swift community adopting a formatting standard. Even better, thereā€™s no built in ā€œset your formatting optionsā€ in Xcodeā€™s Settings that I could see. I know it has options for controlling what rules get applied from a config file, but I hope Apple doesnā€™t push that customisability too much. In my opinion, it would be a step forward for Swift if we could agree on a standard format for Swift code. Unfortunately, getting developers to agree on that is impossible. It will take leadership instead, and Apple should provide that leadership.

As far as I know, thereā€™s no way to tell Xcode to run a command every time you save a file. I looked at whether Behaviours could do it, but I donā€™t believe it can. I hope Apple also add an easy way to perform a command on saving a file.

So if youā€™re reading this inside Apple, or if you know someone there who might have influence in this area, please pass this on. Iā€™d also be more than happy to talk to anyone from that team if they would like to hear an even more passionate version of this intro! šŸ˜‚ I donā€™t expect them to switch the ā€œformat on saveā€ command on by defaultĀ¹, but please give people the option.

Look to the JavaScript and Go communities to see what a success this could be. It will be worth a few weeks of complaints about what the final set of default rules should be, but itā€™ll be a true step forward for more readable Swift code for the rest of time!

ā€”

Ā¹ Yetā€¦ šŸ˜‚

Dave Verwer  

News


Code



Business and Marketing

And finally...

A few days into making One Million Checkboxes I thought I'd been hacked. What was that doing in my database?