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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.