Name
NSArchiver — Mac OS X 10.0
Synopsis
This class is a concrete subclass of NSCoder
used
to archive a network of interconnected objects (an
object tree)
into a data format that can be written to disk. The archive operation
returns an NSMutableData
object containing this
data. To archive an object, the class method
archivedDataWithRootObject
: is used, which returns
an NSData
object containing the archived object.
Alternatively, we can archive directly to a file using the class
method archiveRootObject:toFile
:. It is also
possible to initialize an instance of NSArchiver
with a pointer to an instance of NSMutableData
using initForWritingWithMutableData
:, thus
providing a more persistent archiving engine than if we simply used
the class methods.
To
retrieve objects from an
archive, we use another subclass of NSCoder
:
NSUnarchiver
. NSArchiver
and
NSUnarchiver
support an archival scheme where
objects and variables must be unarchived in the same order that they
were archived. Mac OS X 10.2 introduced keyed-archiving, whereby
every object and variable in an archive has an associated key that
frees us from having to be strictly bound to the original archive
format. This has great benefits for improving the compatability of
data files between versions of an application.
For instances of a class to be archivable, that class must conform to
the NSCoding
protocol. See the
NSCoding
protocol description and Chapter 2 for more information about archiving.
|
@interface NSArchiver : NSCoder
|
|
Get Cocoa in a Nutshell 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.