Calling Swift Concurrency async code synchronously in Swift

Sometimes you just need to shove a round peg into a square hole. Sometimes that genuinely is the best option (or perhaps more accurately: the least bad option). I find my hand is often forced by APIs I don’t control (most often Apple’s APIs). e.g. data source or delegate callbacks that are synchronous and require… Read more

Swift on a Raspberry Pi (in 2024)

Five years ago installing Swift on a Raspberry Pi – or really any non-Apple platform – was fairly involved. Compared to getting a Raspberry Pi working to begin with it was easy, but still a far cry from apt install swift. Sadly it’s still not quite that easy (and some Python package is squatting on… Read more

The only usable ByteCountFormatStyle is decimal

Swift makes it relatively easy to format numbers as byte counts, with appropriate suffixes to indicate units and generally sensible auto-selection of scale factors. e.g.: 1 kB (in English – results may vary depending on locale) This is just a small subset of Swift’s FormatStyle-based formatting capabilities, with which I have a bit of a… Read more

Fucking FormatStyle

I have a bit of a love-hate relationship with Swift’s FormatStyle-based formatting capabilities. 42% (in English – results may vary depending on locale) On the pro side: But the cons are rough: All in all, there’s a reason fuckingformatstyle.com exists (and don’t forget to tip!).

Swift sucks at web serving… or does it?

Chart showing throughput (requests per second) over number of concurrent requests, for four different web servers (representing the programming languages JavaScript, PHP, Kotlin - erroneously labelled as Java on the chart - and Swift).

A few weeks ago, Axel Roest published a simple web server comparison, that turned out to not be doing what it was thought to be doing. Figuring that out was a very interesting discussion that warrants a retrospective, to look at which parts were particularly helpful and which not so much. Tangentially, I want to… Read more

Swift tip: the swap function

The following code prints the Fibonacci sequence. You’ve probably seen it before. It’s one of the simplest and most well-known examples of a sliding window operation – where the next value depends on the preceding two (or more) values. While almost all programs do not calculate the Fibonacci sequence, many do contain similar sliding-window algorithms.… Read more