Class: NSKeyedUnarchiver

Inherits:
NSCoder show all

Overview

NSKeyedUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of named objects (and scalar values) from a keyed archive. Such archives are produced by instances of the NSKeyedArchiver class.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSCoder

#allowedClasses, #allowsKeyedCoding, #decodeArrayOfObjCType:count:at:, #decodeBytesWithReturnedLength:, #decodeDataObject, #decodeIntegerForKey:, #decodeObject, #decodeObjectOfClass:forKey:, #decodeObjectOfClasses:forKey:, #decodePropertyListForKey:, #decodeValueOfObjCType:at:, #decodeValuesOfObjCTypes:, #encodeArrayOfObjCType:count:at:, #encodeBool:forKey:, #encodeBycopyObject:, #encodeByrefObject:, #encodeBytes:length:, #encodeBytes:length:forKey:, #encodeConditionalObject:, #encodeConditionalObject:forKey:, #encodeDataObject:, #encodeDouble:forKey:, #encodeFloat:forKey:, #encodeInt32:forKey:, #encodeInt64:forKey:, #encodeInt:forKey:, #encodeInteger:forKey:, #encodeObject:, #encodeObject:forKey:, #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

+ (Class) classForClassName(codedName)

Returns the class from which NSKeyedUnarchiver instantiates an encoded object with a given class name.

Parameters:

  • codedName (String)

    The ostensible name of a class in an archive.

Returns:

  • (Class)

    The class from which NSKeyedUnarchiver instantiates an object encoded with the class name codedName. Returns nil if NSKeyedUnarchiver does not have a translation mapping for codedName.

+ (Object) setClass(cls, forClassName:codedName)

Adds a class translation mapping to NSKeyedUnarchiver whereby objects encoded with a given class name are decoded as instances of a given class instead. When decoding, the class’s translation mapping is used only if no translation is found first in an instance’s separate translation map.

Parameters:

  • cls (Class)

    The class with which to replace instances of the class named codedName.

  • codedName (String)

    The ostensible name of a class in an archive.

Returns:

+ (Object) unarchiveObjectWithData(data)

Decodes and returns the object graph previously encoded by NSKeyedArchiver and stored in a given NSData object. This method raises an NSInvalidArchiveOperationException if data is not a valid archive.

Parameters:

Returns:

+ (Object) unarchiveObjectWithFile(path)

Decodes and returns the object graph previously encoded by NSKeyedArchiver written to the file at a given path. This method raises an NSInvalidArgumentException if the file at path does not contain a valid archive.

Parameters:

  • path (String)

    A path to a file that contains an object graph previously encoded by NSKeyedArchiver.

Returns:

  • (Object)

    The object graph previously encoded by NSKeyedArchiver written to the file path. Returns nil if there is no file at path.

Instance Method Details

- (Class) classForClassName(codedName)

Returns the class from which the receiver instantiates an encoded object with a given class name. The class’s separate translation map is not searched.

Parameters:

  • codedName (String)

    The name of a class.

Returns:

  • (Class)

    The class from which the receiver instantiates an encoded object with the class name codedName. Returns nil if the receiver does not have a translation mapping for codedName.

- (Boolean) containsValueForKey(key)

Returns a Boolean value that indicates whether the archive contains a value for a given key within the current decoding scope.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Boolean)

    YES if the archive contains a value for key within the current decoding scope, otherwise NO.

- (Boolean) decodeBoolForKey(key)

Decodes a Boolean value associated with a given key.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Boolean)

    The Boolean value associated with the key key. Returns NO if key does not exist.

- (Integer) decodeBytesForKey(key, returnedLength:lengthp)

Decodes a stream of bytes associated with a given key. The returned value is a pointer to a temporary buffer owned by the receiver. The buffer goes away with the unarchiver, not the containing autoreleasepool block. You must copy the bytes into your own buffer if you need the data to persist beyond the life of the receiver.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

  • lengthp (Integer)

    Upon return, contains the number of bytes returned.

Returns:

  • (Integer)

    The stream of bytes associated with the key key. Returns NULL if key does not exist.

- (Float) decodeDoubleForKey(key)

Decodes a double-precision floating-point value associated with a given key. If the archived value was encoded as single-precision, the type is coerced.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Float)

    The double-precision floating-point value associated with the key key. Returns 0.0 if key does not exist.

- (Float) decodeFloatForKey(key)

Decodes a single-precision floating-point value associated with a given key. If the archived value was encoded as double precision, the type is coerced, loosing precision. If the archived value is too large for single precision, the method raises an NSRangeException.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Float)

    The single-precision floating-point value associated with the key key. Returns 0.0 if key does not exist.

- (Integer) decodeInt32ForKey(key)

Decodes a 32-bit integer value associated with a given key. If the archived value was encoded with a different size but is still an integer, the type is coerced. If the archived value is too large to fit into a 32-bit integer, the method raises an NSRangeException.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Integer)

    The 32-bit integer value associated with the key key. Returns 0 if key does not exist.

- (Integer) decodeInt64ForKey(key)

Decodes a 64-bit integer value associated with a given key. If the archived value was encoded with a different size but is still an integer, the type is coerced.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Integer)

    The 64-bit integer value associated with the key key. Returns 0 if key does not exist.

- (Integer) decodeIntForKey(key)

Decodes an integer value associated with a given key. If the archived value was encoded with a different size but is still an integer, the type is coerced. If the archived value is too large to fit into the default size for an integer, the method raises an NSRangeException.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Integer)

    The integer value associated with the key key. Returns 0 if key does not exist.

- (Object) decodeObjectForKey(key)

Decodes and returns an object associated with a given key.

Parameters:

  • key (String)

    A key in the archive within the current decoding scope. key must not be nil.

Returns:

  • (Object)

    The object associated with the key key. Returns nil if key does not exist, or if the value for key is nil.

- (Object) delegate

Returns the receiver’s delegate.

Returns:

  • (Object)

    The receiver’s delegate.

- (Object) finishDecoding

Tells the receiver that you are finished decoding objects. Invoking this method allows the receiver to notify its delegate and to perform any final operations on the archive. Once this method is invoked, the receiver cannot decode any further values.

Returns:

- (Object) initForReadingWithData(data)

Initializes the receiver for decoding an archive previously encoded by NSKeyedArchiver. When you finish decoding data, you should invoke finishDecoding.This method raises an NSInvalidArchiveOperationException if data is not a valid archive.

Parameters:

Returns:

- (Object) setClass(cls, forClassName:codedName)

Adds a class translation mapping to the receiver whereby objects encoded with a given class name are decoded as instances of a given class instead. When decoding, the receiver’s translation map overrides any translation that may also be present in the class’s map (see setClass:forClassName:).

Parameters:

  • cls (Class)

    The class with which to replace instances of the class named codedName.

  • codedName (String)

    The ostensible name of a class in an archive.

Returns:

- (Object) setDelegate(delegate)

Sets the receiver’s delegate.

Parameters:

  • delegate (Object)

    The delegate for the receiver.

Returns: