The Coding interface declares the method that a class must implement so that instances of that class can be encoded and decoded. This capability provides the basis for archiving (where objects and other structures are stored on disk) and distribution (where objects are copied to different address spaces). See the Coder class specification for an introduction to coding.
In keeping with object-oriented design principles, an object being encoded or decoded is responsible for encoding and decoding its instance variables. A coder instructs the object to do so by invoking encodeWithCoder. encodeWithCoder instructs the object to encode its instance variables to the coder provided; an object can receive this method any number of times. Any object class that should be codable must implement the Coding interface.
When an object receives an encodeWithCoder message, it should encode all of its vital instance variables, after sending a message to super if its superclass also conforms to the Coding interface. An object doesn't have to encode all of its instance variables. Some values may not be important to reestablish and others may be derivable from related state upon decoding.
Substitution methods are declared by NextObject, and come in two flavors: generic and specialized. The one generic method is:
The specialized substitution methods are designed for (and invoked by) a specific, concrete coder subclass. Objective-C's NSArchiver invokes replacementObjectForArchiver, while Objective-C's NSPortCoder invokes replacementObjectForPortCoder. (There isn't a specialized version of awakeAfterUsingCoder.) By implementing these specialized methods, your class can base its coding behavior on the specific coder class being used. For more information on these methods, see their method descriptions in the NextObject class specification, as well as the appropriate Foundation Framework Reference documentation.