I seen one thing whereas studying Nezhyborets Oleksii’s newest submit on formatting code throughout a number of strains. He ignored a brand new Xcode characteristic, nevertheless it caught my eye as I’ve been hoping Apple would add this for years!
New in Xcode 16’s “Editor” menu below “Construction” you’ll discover “Format File with swift-format”. 😍 I couldn’t wait to attempt it, so I loaded an Xcode venture, opened a file, and it labored flawlessly! I don’t have swift-format
put in globally on my machine, so Xcode should now bundle a model of the instrument. It seems that it’s now a part of the Swift 6.0 toolchain. Even higher!
Why am I so enthusiastic about this, although? We’ve got been capable of run this instrument for years.
I’m excited as a result of I care about formatting instruments like this turning into trivial to make use of, and even at some point for it to turn into default to run this instrument each time you save a file. 😱
I wrote one thing on “Prettier” a few years in the past, and I’d urge you to re-read it earlier than you proceed. It’ll clarify why I need this a lot, and my emotions have solely turn into stronger about it since then.
Exposing swift-format
in Xcode is the 1st step to that dream of the Swift group adopting a formatting customary. Even higher, there’s no in-built “set your formatting choices” in Xcode’s Settings that I might see. I do know it has choices for controlling what guidelines get utilized from a config file, however I hope Apple doesn’t push that customisability an excessive amount of. For my part, it will be a step ahead for Swift if we might agree on an ordinary format for Swift code. Sadly, getting builders to agree on that’s not possible. It can take management as an alternative, and Apple ought to present that management.
So far as I do know, there’s no option to inform Xcode to run a command each time you save a file. I checked out whether or not Behaviours might do it, however I don’t consider it could actually. I hope Apple additionally add a straightforward option to carry out a command on saving a file.
So when you’re studying this inside Apple, or if you already know somebody there who may need affect on this space, please go this on. I’d even be very happy to speak to anybody from that staff in the event that they wish to hear an much more passionate model of this intro! 😂 I don’t anticipate them to change the “format on save” command on by default¹, however please give individuals the choice.
Look to the JavaScript and Go communities to see what successful this might be. It will likely be price a couple of weeks of complaints about what the ultimate set of default guidelines needs to be, nevertheless it’ll be a real step ahead for extra readable Swift code for the remainder of time!
—
¹ But… 😂