I have a CoreData object Player with a to-many relationship to goals. I am trying to add a goal object like so,
Goal *fg =(Goal*)[self.database createGoalObject]; //Custom function
Player* player = (Player*)[NSEntityDescription insertNewObjectForEntityForName:@"Player" inManagedObjectContext:self.database.managedObjectContext];
[player addGoalsObject:fg];
My app is breaking with the following error:
'NSInvalidArgumentException', reason: '-[__NSCFSet entity]: unrecognized selector sent to instance 0x8d90f00'
A po at the debug prompt shows that 0x8d90f00 is a Goal object. My questions are:
- why is core data sending a message to the Goal object?
- why is the goals relationship for Player initializing to nil? Should it not be an empty set till loaded?
- Do I have to override the addGoalsObject in Player.h to manually set the value?
The error specifically says that something tried to call the
entitymethod on an__NSCFSet. In other words, the object at0x8d90f00is an NSSet of some type.You are being slightly mislead by the output of
po 0x8d90f00because NSSet'sdescriptionmethod will include the description of the objects it contains, wrapped in{(and)}characters.Had you done
po [0x8d90f00 class]it would have respondedNSSetorNSMutableSet.Your createGoalObject is returning a set.