I’ve built a relatively simple Core Data app along the lines of the recipe app. I have an Event entity that has a date attribute and I can add and delete Events to the tableview no problem. I wanted to default the date on new entries to today so I subclassed the Entity NSManagedObject and added an awakeFromInsert method to set the date. That works fine too.
I then wanted to default another property of the Event - the name of a group (of people) - to a value that I’m holding in another Entity/object.
So, in awakeFromInsert, I made an NSFetchRequest, executed it, and got the name value of the first object in the returned results. All seemed fine until I noticed that now, when I click the Add button on the Event table, I get two entries in the table each time.
A little further investigation revealed that there really is only one object, it’s just showing up twice. If I save and restart the program, only one Event shows up. If I add another Event, two entries are shown (for a total of three). If I save and restart though, I only see two. I’ve verified in the XML store that there is only the one event object added for each Add click.
Clearly the TableView is messed up but it seems to be due to the FetchRequest call. If I comment that out, it works fine.
I’m totally stumped on this. Hope someone can shed some light.