April 2015
Intermediate to advanced
556 pages
17h 47m
English
Now that you have taught your Employee object to encode and decode itself, you are now ready to add saving and loading to your application. When it is time to save your employees to a file, your Document class will be asked to create an instance of NSData. Once your object has created and returned an NSData object, it will be automatically written to a file.
To create an NSData object, you will use the NSKeyedArchiver class. NSKeyedArchiver has the following class method:
class func archivedDataWithRootObject(rootObject: AnyObject) -> NSData
This method archives the objects into the NSData object’s buffer of bytes.
Once again, we return to the idea of “I told two friends, and they told two friends.” ...