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

Copy-on-write on APFS

APFS (like many modern file systems but unlike its predecessor HFS+) supports copy-on-write. This means you can logically copy a file – it looks and behaves like a distinct file – but it doesn’t immediately copy the file’s contents on disk – it merely shares them with the original. Only if and as you modify… Read more

Matching prefixes in Swift strings

How do you determine if one string starts with another, in Swift? Surely that’s exactly what the hasPrefix(_:) method is for: No can haz etiquette? Wot? The problem is that hasPrefix is not meant for general use with human text; it’s barely better than a byte-wise comparison. It only guarantees that it won’t be fooled… Read more

Including Services in contextual menus in SwiftUI

Screenshot of the good Services submenu (as found in the application menu), with more options, app icons, and better grouping.

SwiftUI provides a way to provide a contextual menu for a view, with contextMenu(menuItems:) and friends, but it requires you to manually specify the entire contents of the contextual menu. That means it does not include the standard Services submenu. A brief history of Contextual Menus Contextual menus were introduced [to the Mac] in 1997… Read more

Hiding SwiftUI views

There are several ways to hide a SwiftUI view, although they don’t all agree on what it means to hide the view. Do you want it to be invisible, or actually not there? To make it invisible you need only set its opacity to zero or use the hidden modifier. But the view will still… Read more