Debugging Core Data


One of the reasons I’ve toyed with the new app for so long (the idea is about 5 years old), has been that I am struggling to learn Core Data. Not only that, but I’ve been dealing with a ton of day job activities, etc. So I am finally getting this app started. The basic idea behind the application is a header->detail line database challenge, back when I did DB programming this would have been called an invoice problem. In this case, we have from 0 to infinite headers (each one a unique record), and each header can have from 0 to infinite detailed records.

In Core data you would define your entities with Header having a one to many relationship to Detail. And that relationship would be optional, since you could have 0 detailed entities. Right now the application does a good job of showing you a list of the headers, and allowing you to add new headers. My early builds (the ones were I didn’t define the detail records) even let you go back and do a detail view of the headers.

Now when I go to the header views, it crashes while trying to give you a UITableView of the detailed records. Obviously I am not handling Detail records correctly. I’ve been told that these records are an NSSet and should be converted to an Array for UITableView handling. So my current guess is I am not handling an empty Array correctly. I am guessing I need to set it to NIL in the ViewController and then assign data to it in the TableView functions. (I will try that this weekend).

My second crash is when I try to allow a user to delete the Header records. I was able to do this originally, so somehow in my refactoring of the app to add the detail records, I must have screwed something up. I hope to fix this one quickly.

Now the reason I called this post “Debugging Core Data” is because the crashes don’t seem to provide me with a lot of insights, in to what the crash really is, but I find if I try and explain a programming problem I have to someone, I tend to work it out. Let’s hope this worked!