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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:27:09+00:00 2026-06-10T17:27:09+00:00

I need some clarifications from the Apple documentation The fetch request must have at

  • 0

I need some clarifications from the Apple documentation

The fetch request must have at least one sort descriptor. If the
controller generates sections, the first sort descriptor in the array
is used to group the objects into sections; its key must either be the
same as sectionNameKeyPath or the relative ordering using its key must
match that using sectionNameKeyPath
.

I’m using a NSFetchedResultsController with sections in the following way

[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                    managedObjectContext:mainContext
                                      sectionNameKeyPath:@"paymentDate"
                                               cacheName:nil];

As I understood from the doc, the NSFetchRequest I pass in the NSFetchedResultsController must at least a sort descriptors. But since I use sections, the sort descriptor must be like the following:

[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:
        [NSSortDescriptor sortDescriptorWithKey:@"paymentDate" ascending:YES],
        [NSSortDescriptor sortDescriptorWithKey:@"paymentCode" ascending:YES],
        nil]];

If I use sort descriptors like

[fetchRequest setSortDescriptors:[NSArray arrayWithObjects:
        [NSSortDescriptor sortDescriptorWithKey:@"paymentCode" ascending:YES],
        nil]];

I receive an error like the following

NSFetchedResultsController ERROR: The fetched object at index X has an
out of order section name Y. Objects must be sorted by section name’

In my case, using [NSSortDescriptor sortDescriptorWithKey:@"paymentDate" ascending:YES], it allows me to overcome the problem. Maybe I’m only lucky ;).

But, what does it mean or the relative ordering using its key must match that using sectionNameKeyPath? Could you provide me an explanation?

Thank you in advance.

  • 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-06-10T17:27:11+00:00Added an answer on June 10, 2026 at 5:27 pm

    If you are using sections, then the FRC needs to know how to sort the array of data so that it can group all the results by section. Thus, whatever you specify as the first sort descriptor in the fetch request, must match how your sections are to be grouped so that the FRC can do it properly.

    You don’t have to specify they exact field, but the sort order should be the same.

    For example, if your first sort descriptor would group the array by section, even though it did not reference the section, then it would be fine. In most cases, you should explicitly specify your section attribute to remove any possibility for confusion on the part of the FRC — or it will throw an exception.

    EDIT

    For example, let’s say you have two sort descriptors: sd1 and sd2. sd1 uses the same key as provided to the FRC in sectionNameKeyPath. sd2 uses a different key.

    When you sort the entire array, if they both produce a final array that groups the entities in the same sections, then you can use either sd1 or sd2 as the first sort descriptor.

    Basically, they FRC will group the entities into sections based on the sectionNameKeyPath so it can determine how many sections there are, and how many rows are in each section. Thus, the array it gets as input must be sorted into similar groupings, relative to the sectionNameKeyPath.

    As it trolls through the array, it looks at the sectionNameKeyPath and expects to see a specific number of entries with the same sectionNameKeyPath. Thus, the array must be sorted to keep all the sections together.

    If you can accomplish that without specifying the same key as the first sort descriptor, then everything will work fine. If not, then you should use the same section key as the first sort descriptor.

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

Sidebar

Related Questions

Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
Just need some quick clarification I have 2 Queries in my Access Database that
Need some regular expressions help. So far I have my code working to allow
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help to solve this. I have a gridview and inside the gridview
I need some clarification; I have a jar that I built and inside of
I think I need some clarifications regarding WPFs Dispatcher.Invoke and Dispatcher.BeginInvoke usage. Suppose I
I'm pretty much confused on this. Need some clarifications. Example 1 : pgrep string
i need some clarification on how to populate select(s) with data from mysql. Basically

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.