Class: NSKeyedArchiver

Inherits:
NSCoder show all

Overview

NSKeyedArchiver, a concrete subclass of NSCoder, provides a way to encode objects (and scalar values) into an architecture-independent format that can be stored in a file. When you archive a set of objects, the class information and instance variables for each object are written to the archive. NSKeyedArchiver’s companion class, NSKeyedUnarchiver, decodes the data in an archive and creates a set of objects equivalent to the original set.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSCoder

#allowedClasses, #allowsKeyedCoding, #containsValueForKey:, #decodeArrayOfObjCType:count:at:, #decodeBoolForKey:, #decodeBytesForKey:returnedLength:, #decodeBytesWithReturnedLength:, #decodeDataObject, #decodeDoubleForKey:, #decodeFloatForKey:, #decodeInt32ForKey:, #decodeInt64ForKey:, #decodeIntForKey:, #decodeIntegerForKey:, #decodeObject, #decodeObjectForKey:, #decodeObjectOfClass:forKey:, #decodeObjectOfClasses:forKey:, #decodePropertyListForKey:, #decodeValueOfObjCType:at:, #decodeValuesOfObjCTypes:, #encodeArrayOfObjCType:count:at:, #encodeBycopyObject:, #encodeByrefObject:, #encodeBytes:length:, #encodeConditionalObject:, #encodeDataObject:, #encodeInteger:forKey:, #encodeObject:, #encodeRootObject:, #encodeValueOfObjCType:at:, #encodeValuesOfObjCTypes:, #objectZone, #requiresSecureCoding, #setObjectZone:, #systemVersion, #versionForClassName:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (NSData) archivedDataWithRootObject(rootObject)

Returns an NSData object containing the encoded form of the object graph whose root object is given.

Parameters:

  • rootObject (Object)

    The root of the object graph to archive.

Returns:

  • (NSData)

    An NSData object containing the encoded form of the object graph whose root object is rootObject. The format of the archive is NSPropertyListBinaryFormat_v1_0.

+ (Boolean) archiveRootObject(rootObject, toFile:path)

Archives an object graph rooted at a given object by encoding it into a data object then atomically writes the resulting data object to a file at a given path, and returns a Boolean value that indicates whether the operation was successful. The format of the archive is NSPropertyListBinaryFormat_v1_0.

Parameters:

  • rootObject (Object)

    The root of the object graph to archive.

  • path (String)

    The path of the file in which to write the archive.

Returns:

  • (Boolean)

    YES if the operation was successful, otherwise NO.

+ (String) classNameForClass(cls)

Returns the class name with which NSKeyedArchiver encodes instances of a given class.

Parameters:

  • cls (Class)

    The class for which to determine the translation mapping.

Returns:

+ (Object) setClassName(codedName, forClass:cls)

Adds a class translation mapping to NSKeyedArchiver whereby instances of of a given class are encoded with a given class name instead of their real class names. When encoding, the class’s translation mapping is used only if no translation is found first in an instance’s separate translation map.

Parameters:

  • codedName (String)

    The name of the class that NSKeyedArchiver uses in place of cls.

  • cls (Class)

    The class for which to set up a translation mapping.

Returns:

Instance Method Details

- (String) classNameForClass(cls)

Returns the class name with which the receiver encodes instances of a given class.

Parameters:

  • cls (Class)

    The class for which to determine the translation mapping.

Returns:

  • (String)

    The class name with which the receiver encodes instances of cls. Returns nil if the receiver does not have a translation mapping for cls. The class’s separate translation map is not searched.

- (Object) delegate

Returns the receiver’s delegate.

Returns:

  • (Object)

    The receiver’s delegate.

- (Object) encodeBool(boolv, forKey:key)

Encodes a given Boolean value and associates it with a given key.

Parameters:

  • boolv (Boolean)

    The value to encode.

  • key (String)

    The key with which to associate boolv. This value must not be nil.

Returns:

- (Object) encodeBytes(bytesp, length:lenv, forKey:key)

Encodes a given number of bytes from a given C array of bytes and associates them with the a given key.

Parameters:

  • bytesp (Integer)

    A C array of bytes to encode.

  • lenv (Integer)

    The number of bytes from bytesp to encode.

  • key (String)

    The key with which to associate the encoded value. This value must not be nil.

Returns:

- (Object) encodeConditionalObject(objv, forKey:key)

Encodes a reference to a given object and associates it with a given key only if it has been unconditionally encoded elsewhere in the archive with encodeObject:forKey:.

Parameters:

  • objv (Object)

    The object to encode.

  • key (String)

    The key with which to associate the encoded value. This value must not be nil.

Returns:

- (Object) encodeDouble(realv, forKey:key)

Encodes a given double value and associates it with a given key.

Parameters:

  • realv (Float)

    The value to encode.

  • key (String)

    The key with which to associate realv. This value must not be nil.

Returns:

- (Object) encodeFloat(realv, forKey:key)

Encodes a given float value and associates it with a given key.

Parameters:

  • realv (Float)

    The value to encode.

  • key (String)

    The key with which to associate realv. This value must not be nil.

Returns:

- (Object) encodeInt32(intv, forKey:key)

Encodes a given 32-bit integer value and associates it with a given key.

Parameters:

  • intv (Integer)

    The value to encode.

  • key (String)

    The key with which to associate intv. This value must not be nil.

Returns:

- (Object) encodeInt64(intv, forKey:key)

Encodes a given 64-bit integer value and associates it with a given key.

Parameters:

  • intv (Integer)

    The value to encode.

  • key (String)

    The key with which to associate intv. This value must not be nil.

Returns:

- (Object) encodeInt(intv, forKey:key)

Encodes a given int value and associates it with a given key.

Parameters:

  • intv (Integer)

    The value to encode.

  • key (String)

    The key with which to associate intv. This value must not be nil.

Returns:

- (Object) encodeObject(objv, forKey:key)

Encodes a given object and associates it with a given key.

Parameters:

  • objv (Object)

    The value to encode. This value may be nil.

  • key (String)

    The key with which to associate objv. This value must not be nil.

Returns:

- (Object) finishEncoding

Instructs the receiver to construct the final data stream. No more values can be encoded after this method is called. You must call this method when finished.

Returns:

- (Object) initForWritingWithMutableData(data)

Returns the receiver, initialized for encoding an archive into a given a mutable-data object. When you finish encoding data, you must invoke finishEncoding at which point data is filled. The format of the receiver is NSPropertyListBinaryFormat_v1_0.

Parameters:

  • data (NSMutableData)

    The mutable-data object into which the archive is written.

Returns:

  • (Object)

    The receiver, initialized for encoding an archive into data.

- (NSPropertyListFormat) outputFormat

Returns the format in which the receiver encodes its data.

Returns:

  • (NSPropertyListFormat)

    The format in which the receiver encodes its data. The available formats are NSPropertyListXMLFormat_v1_0 and NSPropertyListBinaryFormat_v1_0.

- (Object) setClassName(codedName, forClass:cls)

Adds a class translation mapping to the receiver whereby instances of of a given class are encoded with a given class name instead of their real class names. When encoding, the receiver’s translation map overrides any translation that may also be present in the class’s map.

Parameters:

  • codedName (String)

    The name of the class that the receiver uses uses in place of cls.

  • cls (Class)

    The class for which to set up a translation mapping.

Returns:

- (Object) setDelegate(delegate)

Sets the delegate for the receiver.

Parameters:

  • delegate (Object)

    The delegate for the receiver.

Returns:

- (Object) setOutputFormat(format)

Sets the format in which the receiver encodes its data.

Parameters:

  • format (NSPropertyListFormat)

    The format in which the receiver encodes its data. format can be NSPropertyListXMLFormat_v1_0 or NSPropertyListBinaryFormat_v1_0.

Returns: