A coder that stores an object's data to an archive.


@interface NSArchiver : NSCoder


NSArchiver, a concrete subclass of NSCoder, provides a way to encode objects into an architecture-independent format that can be stored in a file. When you archive a graph of objects, the class information and instance variables for each object are written to the archive. The companion class NSUnarchiver decodes the data in an archive and creates a graph of objects equivalent to the original set.

NSArchiver stores the archive data in a mutable data object (NSMutableData). After encoding the objects, you can have the NSArchiver object write this mutable data object immediately to a file, or you can retrieve the mutable data object for some other use.

In macOS 10.2 and later, NSArchiver and NSUnarchiver have been replaced by NSKeyedArchiver and NSKeyedUnarchiver respectively—see Archives and Serializations Programming Guide.


Initializing an NSArchiver

- initForWritingWithMutableData:

Returns an archiver, initialized to encode stream and version information into a given mutable data object.

Archiving data

+ archivedDataWithRootObject:

Returns a data object containing the encoded form of the object graph whose root object is given.

+ archiveRootObject:toFile:

Creates a temporary instance of NSArchiver and archives an object graph by encoding it into a data object and writing the resulting data object to a specified file.

- encodeRootObject:

Archives a given object along with all the objects to which it is connected.

- encodeConditionalObject:

Conditionally archives a given object.

Getting the archived data


The receiver's archive data.

Substituting classes or objects

- classNameEncodedForTrueClassName:

Returns the name of the class used to archive instances of the class with a given true name.

- encodeClassName:intoClassName:

Encodes a substitute name for the class with a given true name.

- replaceObject:withObject:

Causes the receiver to treat subsequent requests to encode a given object as though they were requests to encode another given object.


Archiving Exception Names

Raised by NSArchiver if there are problems initializing or encoding.


Inherits From

See Also



A decoder that restores data from an archive.


Returns the next object from the coder.