Swift’s native Clocks are very inefficient

Screenshot of Instruments showing the outline view for a Time Profile, expanded to show dozens of spurious, overhead functions taking up the vast majority of the runtime.

By which I mean, things like ContinuousClock and SuspendingClock. In absolute terms they don’t have much overhead – think sub-microsecond for most uses. Which makes them perfectly acceptable when they’re used sporadically (e.g. only a few times per second). However, if you need to deal with time and timing more frequently, their inefficiency can become… 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

Multiple displays on a Mac sucks

So many people I’ve worked with have used multiple displays – typically a matched pair side-by-side – and sworn by them. It’s always mystified me, to be honest. I’ve attempted the multi-display lifestyle a few times over the last thirty years. At first as a bourgeois indulgence, back when even having a single 17″ display… Read more

Apple antitrust & music piracy

The position of many folks – most recently the U.S. Department of Justice – against Apple has drawn an unexpected parallel to that of music pirates in the late 90’s and early 2000’s. If you’re too young to have personally lived that time, just know this key point: back then, buying or streaming music online… Read more

getBitmapDataPlanes can break NSImages & NSBitmapImageReps

Opaque black square.

Today was one of those days where you plan to real make a dent in your todo list, and end up spending the entire day debugging why the hell some images are suddenly rendering as completely opaque black. Long story short, on at least some bitmap images, as soon as you call getBitmapDataPlanes it somehow… 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