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 8346665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:05:34+00:00 2026-06-09T07:05:34+00:00

I’m missing the boat on something that I thought I had the hang of

  • 0

I’m missing the boat on something that I thought I had the hang of and was hoping someone here could help.

I’m using Xcode version 4.4 and my project is using Core Data, Storyboards and ARC.

My project has the following 3 entities.

enter image description here

All works well with the Livestock and Notes entities. But when I try to save data to the Taxonomy entity nothing happens. I get no error but the data is not saved.

Is it ok that I not use an array for the fetched results? Based on my predicate, I’m expecting only one object to be returned so I thought I didn’t need an array. Below is my code that does the saving. I have verified that data is being passed in from the view’s text variables.

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = [appDelegate managedObjectContext];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

fetchRequest.entity = [NSEntityDescription entityForName:@"Livestock" inManagedObjectContext:managedObjectContext];

fetchRequest.predicate = [NSPredicate predicateWithFormat:@"tank == %@ AND type == %@ AND name == %@", self.detailTank, self.detailType, self.detailName];

NSError *error = nil;
Livestock *livestock = [[managedObjectContext executeFetchRequest:fetchRequest error:&error] lastObject];
if (error) {
    NSLog(@"TaxonViewController: saveTaxonomy: Retrieving Livestock Record for saving: error = %@", error);
}

Taxonomy *taxonomy = livestock.taxonChildren;

taxonomy.kingdom = self.kingdom.text;
taxonomy.phylum  = self.phylum.text;
taxonomy.classs  = self.classs.text;
taxonomy.order   = self.order.text;
taxonomy.family  = self.family.text;
taxonomy.genus   = self.genus.text;
taxonomy.species = self.species.text;
taxonomy.common  = self.common.text;
taxonomy.livestockParent = livestock;

error = nil;
if (![managedObjectContext save:&error]) {
    NSLog(@"Taxonomy save error. error = %@, userInfo = %@", error, [error userInfo]);
}    

Any insight is greatly appreciated! Thanks!

UPDATE 1:

Modified code to test for NULL taxonChildren value. This solved it for me. Thanks Jesse!

if (livestock.taxonChildren == NULL) {

    Taxonomy *taxonomy = [NSEntityDescription insertNewObjectForEntityForName:@"Taxonomy" inManagedObjectContext:managedObjectContext];

    taxonomy.kingdom = self.kingdom.text;
    taxonomy.phylum  = self.phylum.text;
    taxonomy.classs  = self.classs.text;
    taxonomy.order   = self.order.text;
    taxonomy.family  = self.family.text;
    taxonomy.genus   = self.genus.text;
    taxonomy.species = self.species.text;
    taxonomy.common  = self.common.text;
    taxonomy.livestockParent = livestock;
}
else {

    Taxonomy *taxonomy = livestock.taxonChildren;

    taxonomy.kingdom = self.kingdom.text;
    taxonomy.phylum  = self.phylum.text;
    taxonomy.classs  = self.classs.text;
    taxonomy.order   = self.order.text;
    taxonomy.family  = self.family.text;
    taxonomy.genus   = self.genus.text;
    taxonomy.species = self.species.text;
    taxonomy.common  = self.common.text;
    taxonomy.livestockParent = livestock;
}
  • 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-09T07:05:38+00:00Added an answer on June 9, 2026 at 7:05 am

    Is your livestock.taxonChildren nil? You’ll have to insert an instance of that object into your context first; it won’t create one automatically, even with a one-to-one relationship.

    Note that you should not test for error like this:

    if (error) { ... }
    

    because error may be garbage when the fetch request is successful. You should instead test the return value:

    NSArray *results = [managedObjectContext executeFetchRequest...]
    if (!results) { ... }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm missing the boat on something here, kids. This keeps rearing its head and
Probably missing something completely obvious here, but here goes. I'm starting out with Spring
Must be missing something really obvious here but how do you change the size
I think I'm missing something basic here. Why is the third IF condition true?
I'm probably missing something easy, but I seem to be blocked here... I have
Am I missing something completely obvious here? My intention is to convert the coordinates
I am probably missing something very simple, but here is the situation: I have
I don't know if I'm completely missing the boat here or what, but I
I think I'm missing something basic here. Any explanation or pointers to previously asked
Apparently I'm missing something obvious here, but would appreciate a quick example. I've got

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.