Archiving data
Quick thoughts as to archiving data:
The best method seems to be saving to the /Caches/ directory of the iPhone application package. Then, to support the new Documents feature is easy – just move a file from /Caches/ to /Documents/ and the file is exported. As for importing, do the opposite, and effectively force a ‘restart’ of the application (by forcing all managers and singletons to reload their data).
The problem with this is the process of saving inside the program. Should it be done every time the stored data is modified? But then, what happens when the data is modified 100+ times per second? The application would attempt to encode the data, and write it to the device 100 times per second. The iPhone would simply crash in this situation (on the simulator it would even be slow! this is an extreme example). Another solution is to provide a superclass to data managing objects, which could control a batch-flow workspace. They could store a boolean as to whether the data should be saved each step or not. Then the saving would look like this:
Disable saving Run loop - modify a bunch of data Enable saving (this would also save the data)
By default, saving should be switched on. Personally, I’d name the methods something like as follows:
[dataObject beginBatchModifications];
for (unsigned i = 0; i < 100; i ++) {
[dataObject removeObjectAtIndex:i];
}
[dataObject finishBatchModificationsAndSave];
This is not a perfect solution, but provides a neat code when finished.

Trackbacks & Pingbacks