Friday, January 10, 2020

KVO, My Enemy

Brent Simmons:

One of the keys to the stability of the shipping versions of NetNewsWire is that we don’t allow KVO (Key-Value Observing).

KVO is a false convenience — it’s often easier than setting up a delegate or old-fashioned notification. But to use KVO is to just ask for your app to crash.

And not just crash, but crash in hard-to-figure-out ways.

Drew McCormack:

As others point out, there are a bunch of issues with the FeedlyOperation class, such as the isAsynchronous override, and not changing to the final state atomically. But I think maybe the biggest problem is the use of Swift key paths. Not sure if that should be supported, but in my testing, it doesn’t work. Changing to strings for the key paths fixed things for me.

I’m not sure what the issue is—perhaps a Swift bug or incorrect property declarations so that there’s disagreement about whether is is part of the property name—but Swift key paths seem to be a common source of problems.

Brent Simmons:

We’re going to write a replacement for OperationQueue.


Update (2020-01-24): Adam Maxwell:

If @brentsimmons is writing an NSOperationQueue replacement, I did that a few years ago, for deployment to Leopard.

Brent Simmons (tweet):

We fixed our mystery KVO crash by writing a replacement for OperationQueue.


MainThreadOperationQueue and MainThreadOperation are part of our RSCore framework.

1 Comment RSS · Twitter

Leave a Comment