I observed one thing whereas studying Nezhyborets Oleksii’s newest put up on formatting code throughout a number of strains. He passed over a brand new Xcode function, but it surely 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 software. It seems that it’s now a part of the Swift 6.0 toolchain. Even higher!
Why am I so enthusiastic about this, although? Now we have been capable of run this software 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 someday for it to turn into default to run this software 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 normal. 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. In my view, it might be a step ahead for Swift if we might agree on a normal format for Swift code. Sadly, getting builders to agree on that’s unattainable. It is going to take management as an alternative, and Apple ought to present that management.
So far as I do know, there’s no strategy 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 simple strategy to carry out a command on saving a file.
So should you’re studying this inside Apple, or if you already know somebody there who might need affect on this space, please cross this on. I’d even be very happy to speak to anybody from that staff in the event that they want to hear an much more passionate model of this intro! 😂 I don’t count on them to modify 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 could possibly be. Will probably be price a number of weeks of complaints about what the ultimate set of default guidelines ought to be, but it surely’ll be a real step ahead for extra readable Swift code for the remainder of time!
—
¹ But… 😂