Developer Documentation
PATH  Mac OS X Documentation > Foundation Reference: Java


[Previous] [Class List] [Next]

NSUnarchiver


Inherits from: NSCoder : NSObject
Package: com.apple.yellow.foundation


Class Description


NSUnarchiver, a concrete subclass of NSCoder, defines methods for decoding a set of Objective-C objects from an archive. Such archives are produced by objects of the NSArchiver class. See the NSCoder and NSArchiver specifications for an introduction to archiving.

General Exception Conditions

While unarchiving, NSUnarchiver performs a variety of consistency checks on the incoming data stream. NSUnarchiver throws an exception when:

For a description of type codes, see the discussion of the @encode() compiler directive in Object-Oriented Programming and the Objective-C Language.

Invoking inappropriate methods can also lead to errors. NSUnarchiver's superclass, NSCoder, provides methods for both encoding and decoding. However, only the decoding methods are applicable to NSUnarchiver; don't send an NSUnarchiver any encode... messages.


Method Types


Decoding objects
unarchiveObjectWithData
unarchiveObjectWithFile
Managing an NSUnarchiver
isAtEnd
objectZone
setObjectZone:
systemVersion
Substituting classes or objects
classNameDecodedForArchiveClassName
decodeClassNameAsClassName
classNameDecodedForArchiveClassName
decodeClassNameAsClassName
replaceObject

Constructors


NSUnarchiver

public NSUnarchiver()

public NSUnarchiver(NSData aNSData)

Static Methods



classNameGloballyDecodedForArchiveClassName

public static String classNameGloballyDecodedForArchiveClassName(String nameInArchive)

Returns the name of the class used when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method returns nameInArchive if no substitute name has been specified using the class method (not the instance method) decodeClassName:asClassName:.

Note that individual instances of NSUnarchiver can each be given their own class name mappings by invoking the instance method decodeClassNameAsClassName. The NSUnarchiver class has no information about these instance-specific mappings, however, so they don't affect the return value of classNameGloballyDecodedForArchiveClassName.

See Also: classNameDecodedForArchiveClassName



globallyDecodeClassNameAsClassName

public static void globallyDecodeClassNameAsClassName(String aString, String aString)



unarchiveObjectWithData

public static Object unarchiveObjectWithData(NSData data)

Decodes and returns the object archived in data. This method invokes initForReadingWithData:: and decodeObject to create a temporary NSUnarchiver that decodes the object. If the archived object is the root of a graph of objects, the entire graph is unarchived.

See Also: - encodeRootObject: (NSArchiver)



unarchiveObjectWithFile

public static Object unarchiveObjectWithFile(String path)

Decodes and returns the object archived in the file path. This convenience method reads the file by invoking NSData's dataWithContentsOfFile: method, and then invokes unarchiveObjectWithData.


Instance Methods



classNameDecodedForArchiveClassName

public String classNameDecodedForArchiveClassName(String nameInArchive)

Returns the name of the class that will be used when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method returns nameInArchive unless a substitute name has been specified using the instance method (not the class method) decodeClassNameAsClassName.

See Also: classNameGloballyDecodedForArchiveClassName



data

public NSData data()



decodeByte

public byte decodeByte()



decodeChar

public char decodeChar()



decodeClassNameAsClassName

public void decodeClassNameAsClassName(String nameInArchive, String trueName)

Instructs the receiver to use the class named trueName when instantiating objects whose ostensible class, according to the archived data, is nameInArchive. This method enables easy conversion of unarchived data when the name of a class has changed since the archive was created.

Note that there's also a class method of the same name. The class method has precedence in case of conflicts.

See Also: decodeClassName:asClassName:classNameDecodedForArchiveClassName



decodeDataObject

public NSData decodeDataObject()



decodeDouble

public double decodeDouble()



decodeFloat

public float decodeFloat()



decodeInt

public int decodeInt()



decodeLong

public long decodeLong()



decodeObject

public Object decodeObject()



decodeShort

public short decodeShort()



encodeByte

public void encodeByte(byte aByte)



encodeChar

public void encodeChar(char aChar)



encodeDataObject

public void encodeDataObject(NSData aNSData)



encodeDouble

public void encodeDouble(double aDouble)



encodeFloat

public void encodeFloat(float aFloat)



encodeInt

public void encodeInt(int anInt)



encodeLong

public void encodeLong(long aLong)



encodeObject

public void encodeObject(Object anObject)



encodeShort

public void encodeShort(short aShort)



isAtEnd

public boolean isAtEnd()

Returns YES if the NSUnarchiver has reached the end of the encoded data while decoding, NO if more data follows. You can invoke this method after invoking decodeObject to discover whether the archive contains extra data following the encoded object graph. If it does, you can either ignore this anomaly or consider it an error.

replaceObject

public void replaceObject(Object object, Object newObject)

Causes the NSUnarchiver to substitute newObject for object whenever object is extracted from the archive. newObject can be of a different class from object, and the class mappings set by the two decodeClassName:asClassName: methods are ignored.

versionForClassName

public int versionForClassName(String aString)




[Previous] [Next]