1
votes

I want to save a Goal and an Actor. The two entities are related with an Responsibility-relationship:

Goal *addgoal = (Goal*)[NSEntityDescription insertNewObjectForEntityForName:@"Goal" inManagedObjectContext:context];

    addgoal.goalNaam = nameTextField.text;
    addgoal.goalId = idField.text;
    addgoal.goalBeschrijving = beschrijvingField.text;

    Actor *addactor = (Actor*)[NSEntityDescription insertNewObjectForEntityForName:@"Actor" inManagedObjectContext:context];

    addactor.actorNaam = responsibleField.text;

    [addgoal addResponsibilityObject:addactor];

the line above ([addgoal addResponsibility:addactor]) is causing the error, what is wrong ?

in Goal.h:

@interface Goal (CoreDataGeneratedAccessors)
- (void)addResponsibilityObject:(Actor *)value;
@end

Error:

2012-08-02 20:57:11.838 Choose3[7434:fb03] -[__NSCFSet entity]: unrecognized selector sent to instance 0x8877810 2012-08-02 20:57:11.840 Choose3[7434:fb03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet entity]: unrecognized selector sent to instance 0x8877810'

2
Somewhere you're trying to call a method named entity but you're calling it on the wrong type of object.Phillip Mills
There's no method 'entity'. Is it necessary to implement '- (void)addResponsibilityObject:(Actor *)value;' ?Fuzej
You'll need to give us the implementation of - (void)addResponsibilityObject:(Actor *)value;Jeff Wolski
Actually, there is a method entity; it exists for a number of different classes related to Core Data. The error message is claiming that entity is being called on a NSSet, which is not one of the classes that has it. Is "Responsibility" a too-many relationship...it's almost as if Core Data is confused about that?Phillip Mills
@JeffWolski, I didn't implement this method, is this necessary ? Right now I tried '[[addgoal mutableSetValueForKey:@"responsibility"] addObject:addactor]; ' instead and still got the same error.Fuzej

2 Answers

5
votes

I just encountered the same problem. The solution here was, that I forgot to check the "To-Many" option in the relationship options within the model inspector.

0
votes

It appears that Core Data is confused about the nature of the Responsibility relationship. I suggest creating NSManagedObject subclasses that match the current state of your data model.

One way to create this error would be to change a to-many relationship into a to-one relationship without re-generating the entity class files.