You can see implementations of encodeWithCoder: and initWithCoder: in the DodgeDemo application, in the class ShoppingCart.
- encodeWithCoder:(NSCoder *)coder { [coder encodeObject:carID]; [coder encodeObject:colorID]; [coder encodeObject:colorPicture]; [coder encodeObject:packagesIDs]; [coder encodeObject:downPayment]; [coder encodeObject:leaseTerm]; } - initWithCoder:(NSCoder *)coder { self = [super init]; carID = [[coder decodeObject] retain]; colorID = [[coder decodeObject] retain]; colorPicture = [[coder decodeObject] retain]; packagesIDs = [[coder decodeObject] retain]; downPayment = [[coder decodeObject] retain]; leaseTerm = [[coder decodeObject] retain]; car = nil; return self; }The Java version of DodgeDemo's ShoppingCart implements these methods instead:
public void encodeWithCoder(Coder coder) { coder.encodeObject(leaseTerm); coder.encodeObject(downPayment); // DodgeDemoJava defines a custom Car object that contains all // info about the car. coder.encodeObject(car); } public ShoppingCart(Coder coder) { super(); leaseTerm = coder.decodeObject(); downPayment = coder.decodeObject(); Car aCar = (Car)coder.decodeObject(); setCar(aCar); }For more information on archiving, see the class specifications for NSCoding, NSCoder, NSArchiver, and NSUnarchiver in the Foundation Framework Reference.
Table of Contents Next Section