• I'm compiling and running the tests from the command line. I've enabled garbage collection as you can see in the compiler invocation on the first line of the listing.
• The object to be archived is an instance of NSColor. In order to use this class, I need to not only import the AppKit but also link against it. I missed that at first.
• Just for fun, I get a color from the "Crayons" color list.
• The last example used NSKeyedArchiver, but since we're not using a key, we can just use NSArchiver.
• The interesting part is where the action happens in:
Essentially, the archiver says to the object: encode yourself! Since NSColor conforms to NSCoding, it should (and fortunately, is) able to do that.
• The encoded color is an NSMutableData object, and can now be added to an array and written to a plist file.
Output:
Code listing: