花花世界蕾 发表于 2015-12-31 12:06:41

Archiving(Chapter 10 of Cocoa Programming for Mac OS X)

  One protocol is NSCoding. If your class implements NSCoding, itpromises to implement the following methods:

   - (id)initWithCoder:(NSCoder *)coder;          - (void)encodeWithCoder:(NSCoder *)coder;  An NSCoder is an abstraction of a stream of bytes. You can writeyour data to a coder or read your data from a coder. The initWithCoder: method in your object will read data from the coder and save that data to itsinstance variables. The encodeWithCoder: method in your object will read its instance variables and write those values tothe coder. In this chapter, you will implement both methods in your Person class.
      NSCoder is actuallyan abstract class. Youwon't ever create instances of an abstract class. Instead, an abstract class hassome capabilities that are intended to be inherited by subclasses. You willcreate instances of the concrete subclasses. Namely, you will use NSKeyedUnarchiver to readobjects from a stream of data, and you will use NSKeyedArchiver towrite objects to the stream of data.
页: [1]
查看完整版本: Archiving(Chapter 10 of Cocoa Programming for Mac OS X)