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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:26:28+00:00 2026-05-31T15:26:28+00:00

Only a little question: I have an Entity X with an to-many relation to

  • 0

Only a little question:

I have an Entity X with an to-many relation to Entity Y

In the viewDidLoad method i fetch all X and sort them by name and ascending and they are displayed in a tableView.

If you choose one of the Xs in the tableView, all relational Y´s are shown in a second tableView.
The result of this fetch also includes all relational Y´s for every X, so i dont have to do an extra fetch for the Y´s – but that leads to my Problem:
The Y´s are in a completly random order (which also changes with every restart of the app) – but i want them sorted by date (<- a attribute in the Y Entity)… how can i do that?

Heres the fetch – code

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Customer" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];

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

NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
    // Handle the error.
}

[self setCustomersArray:mutableFetchResults];

and the result looks something like this:

Entity X-1
 attribute-x-1
 attribute-x-2
 relation-attribute
  relation-entity-y-1
   attribute-y-1
   attribute-y-2
  relation-entity-y-1
   attribute-y-1
   attribute-y-2
Entity X-2
 attribute-x-1
 attribute-x-2
 relation-attribute
  relation-entity-y-1
   attribute-y-1
   attribute-y-2

maybe thats an better example:

Customer
 name: Bert
 age: 10
 customerMeasureRealtions
  Measure
   score: 5
   date: 10.10.2010
  Measure
   score: 9
   date: 20.20.2000
Customer
 name: Steve
 age: 20
 customerMeasureRealtions
  Measure
   score: 7
   date: 07.07.2007

after the fetch the “Customers” are sorted by “name”. But if i access the “Measures” through a “Customer” the order of the “Measures” is random, but i want them sorted by “date”.

the code for accessing the Measures (“customer” is a Customer-Entity-Object or Model),
(“measuresForCustomer” is the customerMeasureRealtions):

- (void)loadMeasureDataForCustomer:(Customer *)customer
{
NSSet *customerSet = customer.measuresForCustomer;
measuresArray = [NSMutableArray arrayWithArray:[customerSet allObjects]];
[measuresTable reloadData];
}
  • 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-31T15:26:29+00:00Added an answer on May 31, 2026 at 3:26 pm

    I think there are two ways you could do this:

    1. Initiate a second query to your db and fetch the “measures” for a given Customer. Have a look at Core data, sorting one-to-many child objects for this.
    2. Transfer the NSSet into an NSArray and sort it in place. An NSSet is always unordered. Have a look at How to sort a NSArray alphabetically?. Or Apple’s documentation: sortedArrayUsingDescriptors in conjunction with a NSSortDescriptor.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only a little question: Why the CFPreferences-API creates multiple files in my
I work with Joomla for some time but I have only little question. How
I have multiple HTML files which vary only by a little - a few
I have very little programming knowledge; only a fair bit in Visual Basic. How
I am trying to work through this question and I have had little success
I am new in iphone development and i have little bit Question. My Question
I have a little simple question. Let's say I have a data object with
I have a little question about MVC: For example if I have a model
i have little question, my log4j.xml configuration is listed below <?xml version=1.0 encoding=UTF-8 ?>
I just have a little question about a query making me crazy. I'm working

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.