objective c - iOS Core Data error - Unacceptable type of value for to-many relationship -
i'm tearing hair out issue, seems should simple. ios / objective c new me, maybe i'm not grasping fundamental.
the problem i've added new entity core data model, , set one-to-many relationship. model had 2 entities had one-to-one relationship.
the players entity new one.
i have uitableviewcontroller i'm saving attributes uitextfields. worked fine original configuration of teams/teamdetails, crashes out following error when add in players entity code:
terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'unacceptable type of value to-many relationship: property = "playerdetails"; desired type = nsset; given type = players;
so, in save method, had:
teams *team = [nsentitydescription insertnewobjectforentityforname:@"teams" inmanagedobjectcontext:self.managedobjectcontext]; teamdetails *teamdetails = [nsentitydescription insertnewobjectforentityforname:@"teamdetails" inmanagedobjectcontext:self.managedobjectcontext]; team.teamdetails = teamdetails;
then go on set attributes like:
team.teamname = teamnametextfield.text; team.teamdetails.managername = managernametextfield.text;
which worked no problem. extend incorporate players entity:
players *playerdetails = [nsentitydescription insertnewobjectforentityforname:@"players" inmanagedobjectcontext:self.managedobjectcontext]; team.playerdetails = playerdetails;
and error above. i've tried following:
[team setplayerdetails:playerdetails];
but doesn't make difference. tried:
nsset *playerdetails = [nsentitydescription insertnewobjectforentityforname:@"players" inmanagedobjectcontext:self.managedobjectcontext];
but again, no difference - still thinks it's getting object of type players rather nsset.
i feel i'm not grasping simple, ge appreciated!
playerdetails
to-many relationship, value of team.playerdetails
set of players, not single player object. can either use
[team addplayerdetailsobject:playerdetails];
or more simply, using inverse relationship:
playerdetails.team = team;
Comments
Post a Comment