O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSKeyedArchiver — Mac OS X 10.2

Synopsis

This class is a concrete subclass of NSCoder that encodes objects and scalar values into a data format that can be stored in a file. NSKeyedArchiver is different from NSArchiver in that each object and scalar in the archive has an associated name or key. These keys make it possible to decode the archive piecemeal; that is, in an order that is different from the original encoding. Clients have the option of picking and choosing which objects to decode. Non-keyed archives suffer from the limitation that the entirety of an archive must be decoded at once, and in the order that it was encoded. Archiving is described in greater detail in Chapter 2.

image with no caption

@interface NSKeyedArchiver : NSCoder
                                  // Initializers
   - (id)initForWritingWithMutableData:(NSMutableData *)data;
                                  // Accessor Methods
   - (void)setDelegate:(id)delegate;
   - (id)delegate;
   - (void)setOutputFormat:(NSPropertyListFormat)format;
   - (NSPropertyListFormat)outputFormat;
   - (void)setClassName:(NSString *)codedName 
                                 forClass:(Class)cls;
                                  // Class Methods
   + (BOOL)archiveRootObject:(id)rootObject 
                                 toFile:(NSString *)path;
   + (NSData *)archivedDataWithRootObject:(id)rootObject;
   + (NSString *)classNameForClass:(Class)cls;
   + (void)setClassName:(NSString *)codedName 
                                 forClass:(Class)cls;
                                  // Instance Methods
   - (void)encodeConditionalObject:(id)objv 
                                 forKey:(NSString *)key ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required