Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:46:45+00:00 2026-06-06T22:46:45+00:00

I am using core data and set up a one to many relationship for

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:46:48+00:00Added an answer on June 6, 2026 at 10:46 pm

    In the first function you have the line

    [_tempSet addObject:@""];
    

    then later:

    [self.team addPlayers:_tempSet];
    

    So your adding an NSString to the players relationship of team, when you need to be adding a Player entity.
    In the first function try something like:

    Player *newPlayer = (Player *)[NSEntityDescription insertNewObjectForEntityForName:@"Player" 
    inManagedObjectContext:managedObjectContext];
    [_tempSet addObject:newPlayer];
    

    But you probably also want to set some attributes for the player, not just add an empty player to the team.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have core data model with two entities that have a many-to-many relationship with
I'm using core data in my app. I have two entities that are related:
I'm currently facing in problem using Core Data. I have two entities A and
I am building a toy app using core data for two entities Log (attributes
I've got a window set up with two NSTableViews. In Core Data I have
I am creating Travel guide app using core data. I have 4 entities CITY
In my Core Data app I am using a FetchedResultsController. Usually to set titles
I am using Core Data and want a Text Label to display how many
Imagine if you will a Core Data app with two entities (Employee, and Department).
Currently I have one managedContext, many NSArrayControllers of entities which are all pretty interrelated,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.