So, I sat down and played with Cocoa a bit more last night. I’ve previously read through Cocoa Programming for Mac OS X which was a really good introduction to Cocoa programming. The problem being, it’s been about six months since I read it. I’m a bit sketchy on the details. May need to go back and review some of the fundamentals.

Anyway, I was trying to work with Core Data to define a model that would have two entities. A spell list and a list of schools. Yea, I’m a geek. I’m looking into gaming software. Finish yer laughing. Now that you’re done, each spell can have an associated school and each school can have many associated spells. Nothing fancy.

When creating new entries we’d have a box to enter the spell name and a drop down to select the school. The drop down should do auto-complete if you type in it and if you enter something that isn’t already in the list it should be added.

This is all well and good. The NSComboBox gives me the features I want for the drop down easy enough. It has the auto-complete and it has the add if missing. The part that tripped me up was that while the add if missing works normally it doesn’t appear to work if you’re using Core Data as the backend. When it tries to add the item to the list it passes an NSString when it should be passing an NSManagedObject which causes an exception to be thrown and nothing happens.

After a bit of hunting I stumbled across some emails where other people were having the same issue. As far as I can tell you just can’t do this with Core Data without a lot of fiddly behind the scenes work. So, looks like Core Data isn’t going to give me the love I was hoping for.

I’ll have to look into another way to save my data. Either using something like YAML or doing the SQLite work myself. We’ll see. But, I’ve got to get better at the basic Cocoa before then anyway.