Important: The information in this document is obsolete and should not be used for new development.
Implemented by |
Various Cocoa classes |
Package | com.apple.cocoa.foundation |
Companion guide |
The NSCoding interface is adopted by classes that can be coded with an NSCoder object. Although the interface technically contains no methods, Java classes must implement the following two methods to be codable:
protected ClassName(NSCoder decoder, long token); |
protected void encodeWithCoder(NSCoder encoder); |
The first is a constructor method where ClassName
is replaced with the name of your class. It is invoked when decoding an object. The method must invoke a similar method of its super class if the super class also implements NSCoding; otherwise, the method needs to invoke another constructor of the super class. The second method is invoked when encoding an object. The method must invoke the some method of its super class if the super class also implements NSCoding.
NSCoding is independent of Java’s own serialization protocol, java.io.Serializable
. Unlike java.io.Serializable
, NSCoding does not mark classes for automatic coding; instead, each class handles its own encoding and decoding operations with the methods described above.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)