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?