CoreDataGeneratedAccessors kicked my ass today

Today I had the task of added a collection (NSSet) of RouteLocationEventEntity’s to another entity (RouteLocationEntity).  I thought this was gonne be easy, I had an example to follow, RouteLocationEntity already had a collection of NoteEntity’s.  Easy!

Step 1. I found this code and duplicated it, easy!

Step 2. Go to the datamodel and add this shit, easy!

Xcode datamodel

Step 3. Debug.  Stop at a breakpoint after calling addRouteLocationEventsObject and po my RouteLocationEntity.  Oh shit…

Why the hell is that collection nil?  The Notes property isn’t nil, it is an empty something or-other.

After fumbling around for a while I noticed something.

I suppose the M means many and the O means one.  I’m feeling pretty smart at this time, because I don’t know how to change it.  So I do what we do so often, dig into the contents of the xcdatamodel file and manually edit it.

becomes this

Now my datamodel looks a little better!

Repeat step 3 from above to have really bad things happen.  Oh yeah, reset the iOS simulator. I forget that every time.  Repeat step 3 again and this time I have RouteLocationEventEntity’s!

So now, I know there must be a way to do that in Xcode, but it was not apparent to me this morning.  I feel stupid for having to ask, but how do you do that in Xcode?