Oct 2017

On Fixing that NSNull Crasher in Overcast

I don’t normally head home after lunch, but today I was on the bus going back to Ballard, about to open iBooks on my phone and get back to reading The Caledonian Gambit (which I’m thoroughly enjoying), when I decided to check Twitter first — and saw Marco’s tweet about Overcast’s oldest crash.

I’ve written before about how I love fixing crashing bugs. Partly because I’m adamant that an app should, at a minimum, keep running — and also because it’s fun detective work. (I’ve even written a series of blog posts on how not to crash in the first place.)

So I took this one as a challenge. Here’s how I figured it out:

  • The exception reported [NSNull doubleValue]: unrecognized selector. Now, NSNull is a stand-alone code smell: there’s hardly ever a time where it should be used. Well, there was that one weird thing with the kerning a long time ago, but that’s about it. This crash is probably not that.

  • Then I looked at the backtrace and saw -[NSRTFWriter writeKern], and then I looked a little further and saw that an NSAttributedString was being exported to RTF, and, furthermore, writeKern probably is writing out the kerning attribute, which was set to NSNull. writeKern was expecting an NSNumber. So that was it.

I replied:

The kerning attribute is NSNull. That used to be the way to specify use font-specified kerning.

And then Marco found the bug and fixed it.

* * *

This is a story about experience and luck, not brains. It’s just that I’ve been working with these APIs for a long time.

Here’s the story behind setting NSKernAttributeName to NSNull. Back in the iOS 6 days, when John and Dave and I were working on Vesper — which used a custom font, Ideal Sans — we noticed that the kerning was fucking awful. We obviously couldn’t ship it like that. We had to either figure out how to fix the kerning or switch to the system font — which would have been heart-breaking, since Ideal Sans was so perfect for this app.

So I searched around until I found that there was a little bit of magic: in our NSAttributedStrings, we needed to set NSKernAttributeName to NSNull to get the font-specified kerning. I tried it — and it worked! We were able to ship with Ideal Sans.

(Here’s a search in Vesper’s code base for that attribute.)

I don’t know if this bit of magic is still needed these days. Hopefully not — because 1) it’s weird to have NSNull have a meaning like this, and 2) NSRTFWriter doesn’t know to expect an NSNull instead of an NSNumber (this should get filed as a Radar).

I no longer remember exactly where I ran across that bit of magic. Memory tells me what it was a slide from a James Dempsey talk somewhere, though I can’t seem to find it right now.

Anyway. This bug was fixed because years ago I was working with type nerds (and I am one myself), and because of James.

Fixing crashing bugs takes a village.


As a young developer I didn’t pay that much attention to accessibility. I figured that most people didn’t need those features, and it was something I could get to later. Plus: adding those features wasn’t easy back in those days.

Things have changed.

For one thing, supporting accessibility features — at least on Macs and iOS — has gotten much easier. It’s almost delightful with how much you get for free and how easy it is to add what’s missing. Apple deserves a huge amount of credit for this.

But there are two bigger things I keep thinking of.

First thing: I want to say that access to computing and communications power is a human right. It’s not, not really — but it would be wrong to deny someone access when, with a little extra work, you could make it work for them.

(Would you be lost without your iPhone? I would be.)

Second thing: accessibility is not just for some small number of people with one specific issue. It’s a diverse set of features and solutions. And everybody — even the youngest and healthiest of us — will eventually rely on some accessibility features if they live long enough.

You may not need it now, in other words, but you will, if you’re lucky. And future-you will be proud of past-you if you cared about it before it was personal.

It’s personal to me now, by the way, at age 49: I use the Dynamic Type feature on my iOS devices to bump up the font size. Though I run into layout bugs from time to time (reported: rdar://34791630), I’m still utterly grateful that the feature exists and that so many developers have adopted it (or done the equivalent in their apps).

Without that feature I’d be an iOS programmer who has a hard time actually using an iPhone. Which would be dumb.