0

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:

  1. why is core data sending a message to the Goal object?
  2. why is the goals relationship for Player initializing to nil? Should it not be an empty set till loaded?
  3. Do I have to override the addGoalsObject in Player.h to manually set the value?
Michael Rivers
  • 920
  • 2
  • 10
  • 17

1 Answers1

1

The error specifically says that something tried to call the entity method on an __NSCFSet. In other words, the object at 0x8d90f00 is an NSSet of some type.

You are being slightly mislead by the output of po 0x8d90f00 because NSSet's description method will include the description of the objects it contains, wrapped in {( and )} characters.

Had you done po [0x8d90f00 class] it would have responded NSSet or NSMutableSet.

Your createGoalObject is returning a set.

Trevor Squires
  • 531
  • 4
  • 7
  • You're right. po 0x8d90f00 is showing the description of the object it contains. po [0x8d90f00 class] does respond with __NSCFSet. Not sure I am any closer to resolving the issue though. – Michael Rivers Mar 08 '14 at 02:08