• 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.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOfy1ebfHLdAI0G5Vf8p1QF1jzJP9EuhOMOO4UhK7_dbofMQB8GLqJDHgIunoAlm4aCbKFEU4az92ilUZqSj2c1RivNHternJxYeo0m4FCvd_Ctf7-ddTJNi3_VMHOAzCmqVXrZG3Jnn6Q/s320/Picture+3.png)
• The encoded color is an NSMutableData object, and can now be added to an array and written to a plist file.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxOv5uMrJ3ryq_TzgTwCMGPj7rhDVgvzY4ZJeCW_asv6EBNrMqImwyYDnzBq6DaJe5aaUz_jFpGF_cbbjG4Rhhh7RwTsl0_0ODj3ShRsy8YvmR8ozUwolWrjeXSZirY35Ww6Pvji1goQuX/s320/Picture+2.png)
Output:
Code listing: