Sunday, October 11, 2015

NSData, My Old Friend

Rob Napier:

I see a lot of Swift devs behaving as though Cocoa has somehow disappeared. Cocoa has become the embarrassing uncle that no one wants to acknowledge, even though he’s sitting right there at Thanksgiving dinner passing you the potatoes. And this is crazy. First, Cocoa is a great framework, filled with all kinds of tools that we use every day, implemented well and refined for years. And second, Cocoa is a required framework, filled with tools that we have to use every day if we want to write apps.

[…]

This “but is it correct?” came up all over the place. Would this operation cause a copy? Exactly how long is an UnsafeBufferPointer valid? There’s a lot of bridging magic in Array, and it’s not always clear what is promised. Testing only gets you so far if the current implementation just happens to work. Sometimes behaviors change just by importing Foundation.

[…]

In the end, I spent hours trying to be certain of the precise behaviors of Array bridging and copying. And all that to replace NSData code that is perfectly fine.

1 Comment RSS · Twitter

I wonder if the open-source Linux version of Swift that Apple promised us will include NSData. Knowing how to use Swift without Cocoa could become a useful skill soon enough.

Leave a Comment