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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:20:38+00:00 2026-06-05T16:20:38+00:00

I have a Core Data class Meeting with a property date which I want

  • 0

I have a Core Data class “Meeting” with a property “date” which I want to display in a TableView using a NSFetchedResultsController. The meetings should be sorted in two ways: At first all meetings of a month should be summerized in the same section and all meetings in a month/section should be sorted by date.

    NSComparisonResult (^periodSortBlock)(id, id) = ^(id obj1, id obj2) {                
        NSLog(@"Debug");            

        NSDate *date1 = (NSDate *)obj1;
        NSDate *date2 = (NSDate *)obj2;

        // Pseudocode
        Month *month = [Month monthWithDate:date1];
        NSComparisonResult result = NSOrderedSame;

        if ([Month date:date2 afterDate:month.end])
            result = NSOrderedAscending;
        else if ([Month date:date2 beforeDate:month.start])
            result = NSOrderedDescending;

        return result;
    };        

    NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Meeting"];        
    fetchRequest.predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", self.meetings];

    NSSortDescriptor *sectionByMonth = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:false comparator:periodSortBlock];
    NSSortDescriptor *sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:false];

    fetchRequest.sortDescriptors = [NSArray arrayWithObjects:sectionByMonth, sortByDate, nil];

    frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"date" cacheName:nil];
    [frc performFetch:nil];

The code compiles without any error but the sorting does not work as expected: Every meeting is has its own section.

As far as I can see the sorting block is completely ignored and not called: The NSLog statement does not produce any output and an breakpoint within the block does not stop the execution.

Instead of sortDescriptorWithKey:ascending:comparator: I could use sortDescriptorWithKey:ascending:. The result is exactly the same.

If the block is declared directly in the sortDescriptorWithKey:ascending:comparator: statement or as a variable (like above) does not make any difference as well.

Defining the block as (NSDate*, NSDate*) instead of (id, id) is also no difference.

What is going wrong here? I would understand if the sorting within the block would produce some errors. But how is possible that the block it not called?

  • 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-05T16:20:40+00:00Added an answer on June 5, 2026 at 4:20 pm

    Thanks to the hint from Paul I was able to figure out what the problem is. The solution can be found in the Apple docs (have a look at the “Fetch Predicates and Sort Descriptors” section).

    I thought the the NSFetchRequest would just use SQL to fetch the Objects from the SQLite DB and then use the SortDiscriptors to sort the fetched objects in memory. This is not true: It seems that the complete sorting work is handed over to the SQLite store as well. Of course the Obective-C statesments form the block cannot be translated into a SQL query and thus the block is ignored.

    • 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
Ok here goes my situation: I have a core-data generated class Quantity which has
I have a core data class Game which has a to-many relationship to another
I have a class(Core Data Generated): @interface Place : NSManagedObject @property (nonatomic, retain) NSString
I have a helper class designed to get data from Core Data and pass
I have a Core Data store which contains a number of MediaItem entities that
I'm using Core data on my app ok, i have a problem when saving
I have setup Core Data for an iPhone app without an instance of NSFetchedResultsController.
I have a Core Data app with a fairly simple data model. I want
I have an iPhone/iPad app which uses Core Data. In my DB I have

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.