Issue 682
11th October 2024
Written by Dave Verwer
Comment
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
Sponsored Link
Add paywalls in one line of codeTake the pain out of configuring and testing your app’s paywalls. With RevenueCat Paywalls you can remotely configure and edit your entire paywall view without waiting on App Review. See how it works here.
News
A Cozy WWDCI’m really happy to see Apple experimenting with in-person events again. I wonder if we’ll see more of these happen, maybe even outside of Cupertino?
It was a fantastic experience, and I hope Apple holds many more like it.
Thanks to Todd Heberlein for writing up his experience at the event. It sounds like this event was a great success. 👍
Swift Student Challenge 2025
In a change from previous years, Apple is announcing the Swift Student Challenge early this year. Really early! Applications for the challenge don’t open until February next year, so why talk about it now? From reading this news post, the intention is to give people a chance to learn Swift now to be ready to go in the February submission window. The “Get Ready” page is also updated with a new “Swift Coding Clubs” section. Do you know anyone who might want to learn the language? There are some great resources here.
Code
GenesisThis new tool from Alejandro Martínez is not the first static site generator for Swift. Not by a long way! But it is the newest, and it takes quite a different approach to the alternatives in that it’s a very bare bones approach. Everything is just a String! There’s also a lengthy post explaining some details and the thought process behind it, which you’ll want to read, too!
Recap
There’s not much to say about this new library from Joe Fabisevich, and that’s a good thing! It’s so easy to describe what it does. I’d go with “Add Apple-inspired What’s New screens powered by Markdown to your app”. There’s more to it, like in-built version history and UI customisation, but you should know if you want it from the simple description.
How to keep Date’s microseconds precision in Swift
When I saw the title of this post from Toomas Vahter I almost dismissed it as being intended for someone else. I’m not doing any timing-critical maths with Date, and I’d bet you’re not either. I read it anyway, though, and you also may find the knowledge inside useful, even if you didn’t think it would be from the title!
Business and Marketing
12 Bite-Sized App Marketing LessonsThere’s some especially good advice around email lists (essential!) and paid marketing in this post from Jordan Morgan. There should be a 13th rule, though. Write a blog post like this that markets your app and is interesting enough to share to other people in the industry who might have kids. 👍
And finally...
A few days into making One Million Checkboxes I thought I’d been hacked. What was that doing in my database?