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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:07:36+00:00 2026-05-27T23:07:36+00:00

upon loading the Root View Controller a Managed Object called Target should be created

  • 0

upon loading the Root View Controller a Managed Object called Target should be created using the convenience method:

- (void)viewDidLoad {
    [super viewDidLoad];

    if (context == nil) { 
       context = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    }

    if ([fetchedResultsController.fetchedObjects count] < 1) {
       Target *aTarget = (Target *)[NSEntityDescription insertNewObjectForEntityForName:@"Target" inManagedObjectContext:context]; 
    }

    NSError *error; 
    if (![[self fetchedResultsController] performFetch:&error]) {
       // Update to handle the error appropriately.
       NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    }

     if(![context save:&error]){  
       //Handle error.
     } ...

If I run the App on my iPhone from Xcode it works all fine. However, if I stop the test run and restart the App on the iPhone a new Managed Object is created even though the condition

[fetchedResultsController.fetchedObjects count] < 1) 

does not seem to be satisfied (in the end it is, I just don’t know why). Once the App runs on the Phone independent of Xcode I can close and restart it without increasing the number of Managed Objects created. Only the first time after disconnecting it from Xcode.
Remark: The disconnection from Xcode causes the Segmentation fault: 11 error which also appears when I disconnect another Core Data App from Xcode. So I wouldn’t attribute this error to my problem.
Any ideas how to prevent the App from creating this additional object? Would you need more code to figure out the issue? Thanks a lot.

  • 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-05-27T23:07:37+00:00Added an answer on May 27, 2026 at 11:07 pm

    Solely based on the code I can see, I would think that this piece of code will create a new object the first time the code runs each time the app is run.

    Try switching your 2nd and 3rd if statements so that you’re performing the fetch first. I’d give you code but the code formatting is turning out to be a real pain to use from my iPad.

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

Sidebar

Related Questions

I was getting the following message upon creating a new view controller. Everything was
im using jqueryui dialog but there's a problem upon loading it from other file.
There is a list view and this is loaded dynamically upon loading the page.
Upon loading into a C++ program a Prolog program that contains the command 'send'
I need some help on showing Progress bar upon loading data on my DataGridView.
I need to populate several comboboxes in an Excel sheet upon loading it. I
I'm trying to update a cell in jqgrid permanently upon loading. I know I
So, the app I am working on starts out with a regular view controller
i got out of memory exception upon loading image from file.. i retrieve the
SECOND EDIT It seems that upon loading the page, not when submitting, that the

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.