Extending NSCoding

NSCoding is used often through many iOS, macOS, watchOS and tvOS apps, and usually results in instances that conform being archived into data for transportation or persisting.

So lets extend NSCoding so we can easily archive that object. It’s very simple but very useful:

Now any type that conforms to Archivable will have to conform to NSCoding and will also be easily archived by calling instance.archivedData. Because we’ve extended the protocol itself, all types that declare they conform get this behaviour for free. Neat ?

Kane Cheshire

Author: Kane Cheshire

I’m a software developer (and sort of designer) from Hertfordshire.

I spend a lot of time learning, travelling and flying my drone.
I made MacID. You can check out some of my favourite photographs from travelling at http://kane.codes.

I’m also the creator and lover of Twicnic, an annual Twitter picnic event.

Leave a Reply

Your email address will not be published. Required fields are marked *