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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:17:01+00:00 2026-05-24T14:17:01+00:00

Maybe I’m not going about showing a detail for a selected row using CoreData,

  • 0

Maybe I’m not going about showing a detail for a selected row using CoreData, but I can’t figure out why I’m getting a “BAD_ACCESS” error. I’ve googled around and can’t find what I’m looking for.

Basically I use CoreData to populate the data for a Table View. It retrieves all of the title attributes for all of the entities. When the user clicks on a row, I have a Detail View that needs to show the description for that entity. I think I need to make a new NSManagedObjectContext and a new NSEntityDescription for a new NSFetchRequest in my DetailViewController and then use a NSPredicate to say “where title = [user selected title]”. I get an error when I select a row. See code:

- (void)viewDidLoad
{
    // Do any additional setup after loading the view from its nib.

    // Get the objects from Core Data database
    Caregiver_Activity_GuideAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    NSEntityDescription *entityDescription = [NSEntityDescription
                                              entityForName:@"Definition"
                                              inManagedObjectContext:context];
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entityDescription];

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(title = %@)", self.title];
    [request setPredicate:pred];

    NSError *error;
    NSArray *objects = [context executeFetchRequest:request error:&error];
    if (objects == nil) {
        NSLog(@"There was an error!");
        // Do whatever error handling is appropriate
    }

    for (NSManagedObject *oneObject in objects) {
        [definitionDescriptionTextView setText:[oneObject valueForKey:@"desc"]];
    }

    [objects release];
    [request release];

    [super viewDidLoad];
}

I comment out that code and everything works. But when I try to debug with breakpoints, nothing catches. So I’m more confused.

I know CoreData is probably overkill for what I’m doing but this is a learning app for me.

EDIT: I didn’t include that I’m using a sqlite database that is pre-populated with the entities.

You can also download my project on my github page.

  • 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-24T14:17:02+00:00Added an answer on May 24, 2026 at 2:17 pm

    Normally, with a Core Data backed Master-Detail interface, you don’t fetch for the Detail view.

    When you select a row in the Master tableview, you are selecting a particular managed object instance. You then pass that managed object instance to the detail view. There is no need to refetch the object that you selected in the tableview.

    A good example of this would be the Contacts app. The Master tableview would be a list of Contact objects (displaying the name.) When you select a row, the Master tableview controller takes the specific Contact object associated with the selected row and then passes it to the Detail view controller which then populates the Detail view using data taking from the properties of the passed Contact object.

    So, that entire code block where the error occurs is unnecessary.

    However, the immediate error in this code is that you are releasing an object you didn’t create. In this line:

     NSArray *objects = [context executeFetchRequest:request error:&error];
    

    … you are not creating a NSArray instance with a init, new or create method. Instead, you are merely receiving an autoreleased NSArray instance created and returned by the context NSManagedObjectContext instance. When you release an object you did not create here:

     [objects release];
    

    … you cause the crash.

    Conversely, you do create a NSFetchRequest here:

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

    … because you used init so you do have to balance that with:

    [request relwase];
    

    BTW, this type of code should not be put in viewDidLoad as the method is only called when the view is read in the first time from the nib file on disk. That is only guaranteed to happen once as the view may remain in memory when the user switches to another view. Instead, put code that needs to run each time the view appears in viewWillAppear.

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

Sidebar

Related Questions

Maybe it's a simple question but I can't figure out the right way to
Maybe this question is duplicate, but I can not find an answer for my
Maybe my English is poor but I really cannot figure out what the indeterminate
Maybe the need to do this is a 'design smell' but thinking about another
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe this cannot be done, but please help or suggest how this can be
Maybe I am out of my mind right now, but I have a question
Maybe, it is a stupid question but I can't use python eggs with IronPython.
Maybe this is just obvious to everyone but can someone explain where XOR (or
Maybe someone can help me out. I have created a simple web user control,

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.