2010

2009

2007

2006

2005

Subtle Errors and CoreData

Entry published dec 18 2005

Ideally in Kiwi, everything would be pulled from the server during launch, but this limits Spotlight integration and it makes offline reading of e-mail impossible. I originally toyed around with storing e-mail in the MH mail format because it’s an open format and every message has it’s own file. Persistence is never easy, especially when people demand stability, and implementing the MH format is no exception. Knee deep into writing file I/O code, I took a step back and rewrote with CoreData.

Previously, the interface fed off of instance variables in objects via bindings. It was clear that this was making persistance and multithreading more complex than necessary. So I packaged all the code together that performs IMAP calls and sat it on top of CoreData. Now, instead of writing retrieved IMAP data to local instance variables, it writes directly to the CoreData store. The interface sits on top of a copy of the CoreData store and feeds off of it with Cocoa bindings.

If I had used the MH format, I would have had to manage all of the relationships between Folders and Messages and more importantly, I also would have to insure consistency in the event of crash. CoreData has been a huge help in this regard, it maintains the referential integrity for me and it keeps changes in memory until they are committed. Now users of Kiwi can be confident that their data is stored in a SQLlite database that is consistent across sessions.

Moving from a graph of NSObjects in memory to CoreData has not been without trial and error, though. For about the past day, I’ve been trying to figure out why one table hasn’t been displaying data that exists in the database. I double checked all of my connections, I tripled checked my methods and still, the table was displaying a lone and empty cell. Finally, today I figured it out: I had forgotten to switch the controller in Interface Builder from Class Mode to Entity mode. I made the simple switch, and my tableview (thankfully) came to life.

I have to say that these new technologies, like Bindings and CoreData, solve problems but they also introduce yet another learning curve for developers on the Mac platform. In the end however, I think CoreData is going cause alot of developers out there to take a second look at their persistence code and wether CoreData and Bindings can help them spend more time on other features.

← Previous: Another day and more progress.  //  Next: Why I chose CoreData over Maildir

comments