Encoding and Decoding

The Cocoa frameworks provide a convention for initializing an object instance by decoding data that has previously been encoded. Encoding and decoding object-instance data is the basis for storing objects on disk, and copying objects to different address spaces. Each class is responsible for encoding and decoding its own state by implementing two methods, -encodeWithCoder: and -initWithCoder:, which are declared in the NSCoding protocol. These methods are automatically called, under certain circumstances, by Cocoa framework classes such as NSCoder, NSArchiver, and NSUnarchiver. Almost all classes in the Cocoa frameworks conform to the NSCoding protocol and implement the two coding methods.

A file or block of memory that ...

Get Cocoa® Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.