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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:30:34+00:00 2026-05-31T10:30:34+00:00

I could use some assistance in debugging a EXC_BAD_ACCESS error received on the [context

  • 0

I could use some assistance in debugging a EXC_BAD_ACCESS error received on the [context deleteObject:loan]; command. The error is received in the following delegate method:

- (void)didCancelNewLoan:(Loan *)loan {
    // save the context
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    [context deleteObject:loan];  // *** EXC_BAD_ACCESS here ***

// This method is called from a the following method in a second class:

- (IBAction)cancel:(id)sender {
    [delegate didCancelNewLoan:self.loan];
}

// The loan ivar is created by the original class
// in the below prepare for Segue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"NewLoan"]) {
        UINavigationController *navController = (UINavigationController *)[segue destinationViewController];
        LoanViewController *loanView = (LoanViewController *)[[navController viewControllers] lastObject];
        loanView.managedObjectContext = self.managedObjectContext;
        loanView.delegate = self;

        loanView.loan = [self createNewLoan];
        loanView.newLoan = YES;
    }


// Finally, the loan is created in the above
// method's [self createNewLoan] command:

- (NSManagedObject *)createNewLoan {
    //create a new instance of the entity managed by the fetched results controller
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
    NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
    [newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];

    CFUUIDRef uuid = CFUUIDCreate(NULL);
    CFStringRef uuidstring = CFUUIDCreateString(NULL, uuid);
    //NSString *identifierValue = (__bridge_transfer NSString *)uuidstring;
    [newManagedObject setValue:(__bridge_transfer NSString *)uuidstring forKey:@"identifier"];
    CFRelease(uuid);
    CFRelease(uuidstring);

    NSError *error;
    [self.fetchedResultsController performFetch:&error];
    NSLog(@"%i items in database", [[self.fetchedResultsController fetchedObjects] count]);

    return newManagedObject;
}

Appreciate your looking at the above methods.

  • 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-31T10:30:35+00:00Added an answer on May 31, 2026 at 10:30 am

    From looking at your code above, there’s nothing that stands out as being done incorrectly.

    I am wondering whether you are dealing with two different managed object contexts without realising it? You will have to set some breakpoints where you create the Loan object and see if that might be the case.

    Also why do you have to get a reference to the context via fetchedResultsController if you already have a declared property for it in self.managedObjectContext ?

    The other thing is why do you need to call the fetchedResultsController to performFetch: again when you create a new Loan object? Is your data presented in a table view and have you implemented the NSFetchedResultsController delegate methods?

    That call seems unnecessary and it may be causing issues with the cache created by the fetch. See section “Modifying the fetch request” under this link http://developer.apple.com/library/ios/documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40008227-CH1-SW24

    Finally, try your delete operation directly in the view controller that received the action rather than pass it to the delegate (just to eliminate the possibility that something has been dealloc’d without you knowing).

    Here’s what I’d do:

    - (IBAction)cancel:(id)sender 
    {
        NSError *error;
        NSManagedObjectContext *context = [self.loan managedObjectContext];
        [context deleteObject:self.loan];
        if (![context save:&error])
             NSLog (@"Error saving context: %@", error);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the following error and could use some help resolving it. Anyone
I could use some help. After a few frustrating days of trial and error,
I could use some assistance with my XML transformation, I've viewed other similar questions
After two days of searching, I'm stuck and could really use some assistance. I
I could use some help with expression conversion. I have a method on a
I could use some help writing a regular expression. In my Django application, users
I could use some help creating an XSL template that will take a string
We're having a small issue and could use some help - we have the
i have an issue i could use some help with, i have python list
I'm new to SQL and could use some help in creating a database schema

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.