Radio Bantik:
Days in the Life of an Alpha Geek

Corey Ehmke’s home on the web since 1996, IdolHands.com is an alpha-geek blog covering topics in Ruby on Rails development, Mac OS X, electronics, robotics, and other stuff important in the life of a technologist and tinkerer.

That Core Data Glow

Posted by Corey Ehmke on September 3rd, 2006 in General Tech & Development | Permanent Link | Share/Save

I’m a 13-year veteran of web development (currently doing WebO) but a complete newcomer to Cocoa. Since WWDC I’ve been tackling learning Objective-C. I learn best by doing, so I thought up a little app that I could write while learning the language.

I was sitting on the porch having a cigarette, staring at my notebook and trying to figure out my object model. I was really afraid of making the wrong choice with the “isa” hierarchy and ending up with a really kludgy model. “Isa” doesn’t express relationships the way I want to with my application’s entities.

If this were a web app, I would have separate database tables for each entity, and lookup tables mapping the relationships. In the web app these tables would of course be represented as objects, and their relationships would be handled by the object graph.

But this isn’t going to be a web app, so how am I going to create that object graph with all of its relationships?

The term “Core Data” popped into my head, but I didn’t know anything about it other than the fact that it was featured in several sessions on the WWDC schedule.

A single Google search later, and I found an incredible tutorial by Scott Stevenson at Cocoa Dev Central called “Build a Core Data App“. The graphic in the header showed an entity diagram… and I knew that this was what I was looking for.

The tutorial walked me through creating a sample blogging app that has Topic, Post, and Author entities, each with attributes and relationships. The data modelling is done in XCode– which I didn’t even know was possible– and then the data model is available to Interface Builder to bind to the view.

At a couple of milestones in the tutorial Scott recommends building and running the application to see how things are coming. The first time I did this, I entered a few lines of random text and played with the interface before quitting and resuming the tutorial. The second time I compiled and ran the app… the data from the first run was still there. This freaked me out. Sure enough, there was an XML file in ~/Library/Application Support/BlogDemo/ with my junk data in it.

Core Data is going to make a huge difference in the way I approach Cocoa in general and my app in particular. I’m particularly grateful to Scott Stevenson for his clear writing and illustration.


Leave a Reply

You must be logged in to post a comment.