Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

NSMutableSet Core Data

geiger10dgeiger10d Posts: 97Registered Users
I am using core data and set up a one to many relationship for one of my entities. I have two entities. "Team" and "Player" I am trying to add an NSMutableSet of players to the team.

Below is how I am attempting to add a player to the team.

-(void)addPlayerButton {

[_tempSet addObject:@\"\"];

NSLog(@\"number of cells in _tempSet is:%i\",[_tempSet count]);

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];

}

This is how I am saving

-(void)saveButtonWasPressed {

self.team =[NSEntityDescription insertNewObjectForEntityForName:@\"Team\" inManagedObjectContext:self.managedObjectContext];

self.player = [NSEntityDescription insertNewObjectForEntityForName:@\"Player\" inManagedObjectContext:self.managedObjectContext];
[team addPlayersObject:player];

team.schoolName = _schoolName.text;
team.teamName = _teamName.text;
team.teamID = _teamName.text;
team.season = _season.text;
team.headCoach = _headCoach.text;
team.astCoach = _assistantCoach.text;

player.firstName = cell.playerFirstName.text;
player.lastName = cell.playerLastName.text;
player.number = cell.playerNumber.text;

[self.team addPlayers:_tempSet];


[self.managedObjectContext save:nil];
[self.navigationController popViewControllerAnimated:YES];
}

There are two things going wrong, one, the _tempSet only adds one object and can not add anymore. and the second crashes when I click save right before the line [self.team addPlayers:_tempSet]; With the error [__NSCFConstantString _isKindOfEntity:]: unrecognized selector sent to instance 0xd7cd8'

I am relatively new to Core Data so please feel free to correct me if I am doing something else wrong...
Post edited by geiger10d on

Replies

  • FstuffFstuff Posts: 154Registered Users
    It's not Core Data that you appear to be having trouble with.
    the _tempSet only adds one object and can not add anymore.
    One of the hallsmarks of a set is that it contains distinct objects -- meaning that no two objects in the set are equal to each other. The only line of code that you posted where objects are added to your '_tempSet' adds a static string. So, no matter how many times you call [NSSet addObject], there will only be one occurrence of the string " " in your set. See the apple documentation for more details. https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Collections/Articles/Sets.html#//apple_ref/doc/uid/20000136-CJBDHAJD
    and the second crashes when I click save right before the line [self.team addPlayers:_tempSet]; With the error [__NSCFConstantString _isKindOfEntity:]: unrecognized selector sent to instance 0xd7cd8'
    I assume this is a roundabout way of saying the crash is happening on this line:
    player.number  = cell.playerNumber.text;
    Have you checked to ensure that the type of player.number is the same as the type of cell.playerNumber.text? Furthermore, what is cell? This looks a little suspect.
Sign In or Register to comment.