Data model objects
As I mentioned, the individual transactions in the checkbook are represented by instances of a class, CheckbookItem. This is so we can register with the class to be informed when the user changes something.
To use a class in this way, there is really no code needed. We just use @property and @synthesize as usual. Because it's a class object rather than an array of strings and numbers, we can't just do
[array writeToFile:fn atomically:YES]. Instead, we'll use an NSData object to "freeze-dry" our array of objects.
To do this, we need to teach the class how to encode itself using two required methods:
- (void)encodeWithCoder:(NSCoder *)coder
- (id)initWithCoder:(NSCoder *)coder
We feed the encoder things it knows how to encode, along with a key to remember them by. When we load the data from a file, we use the same keys to get the objects back.
Here is the interface and implementation for CheckbookItem: