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

  • Home
  • SEARCH
  • 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 6737219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:13:24+00:00 2026-05-26T11:13:24+00:00

I have core data entity: mole, which I display in a TableView. When I

  • 0

I have core data entity: “mole,” which I display in a TableView. When I select each in turn, I pass the selected mole to the next NIB using …

controller.mole = [moleArray objectAtIndex:indexPath.row]; // pass the relevant mole to next NIB

When second NIB loads, I want to retrieve just the “details” for just the “mole” selected. I am using the following:

NSManagedObjectContext *context = [mole managedObjectContext]; // find details for the selected mole

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

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Details" inManagedObjectContext:context];
[request setEntity:entity];

// now sort

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"detailsDate" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];

// Having created a fetch request, you now execute it. The events array needs to be mutable, so make a mutable copy of the result.

NSError *error = nil;
NSMutableArray *mutableFetchResults = [[context executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {

    NSLog(@"details mutableFetchResults = nil");

}

// The final steps are to set the view controller’s events array instance variable and to release objects that were allocated.

[self setDetailsArray:mutableFetchResults];
[mutableFetchResults release];
[request release];

Trouble is the “detailsArray” is returning the Details of all the Moles. I cannot seem to retrieve the Details for just the specific Mole selected. I presume setting “context” is incorrect. Help appreciated.

  • 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-26T11:13:24+00:00Added an answer on May 26, 2026 at 11:13 am

    Does the Mole entity have a to-many relationship with Details? If so, you can traverse that relationship and not have to execute a fetch request. Let’s say you do have such a relationship and that it’s called details. You can do this:

    NSSet *details = [mole valueForKey:@"details"];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"detailsDate" ascending:NO];
    NSArray *detailsArray = [details sortedArrayUsingSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
    // [sortDescriptor release];  if you're not using ARC
    

    The trick is that relationships are modeled as NSSet objects, so you’ll still need to sort the value to get an ordered array.

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

Sidebar

Related Questions

I have a Core Data entity which needs a gender property. I just need
I have an Core Data Entity with a number of attributes, which include amount(float),
I have a Core Data entity which has a date attribute. I would like
I have a Core Data Entity which has three properties startDate, endDate and duration.
I have a core data entity which has an exclusive one to many relationship
I have a Core Data model in which a Task entity includes an optional
All, I have a core data entity, CreditCard , and each entity has four
I have a core data entity named Folder. Each Folder has a 1-to-many relationship
I have a document-based Core Data app. My main Core Data entity has several
I have an entity in core data that has 2 Attributes. One that is

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.