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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:49:20+00:00 2026-06-16T22:49:20+00:00

I have an NSFetchedResultsController which I use to fetch my core data and populate

  • 0

I have an NSFetchedResultsController which I use to fetch my core data and populate a table.

To sort the data currently I am using the code below:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"month" ascending:YES];
NSArray *sortDescriptors = @[sortDescriptor];

[fetchRequest setSortDescriptors:sortDescriptors];

month is a NSString of the months of the year and so this currently sorts the months of the year alphabetically.

But what I would like to happen is for the months to be shown in order of closest to todays date.

For example if todays month was April, April would be showed at the top followed by May, June, July etc.

Any help is appreciated, Thanks!

  • 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-16T22:49:21+00:00Added an answer on June 16, 2026 at 10:49 pm

    Custom descriptors aren’t hard but I don’t think a custom SortDescriptor is usable in your case (core data sort descriptors can’t run custom code AFAIK)


    anyways:

    toimplement the descriptor passing it a custom comparator block that returns how the obj1 and obj2 are related to each other

    sample code:

    id desc = [[NSSortDescriptor alloc] initWithKey:@"month" ascending:YES comparator:^NSComparisonResult(id obj1, id obj2) {
        ...
    }];
    

    retval:

    typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently using Core Data . I have one table in which I am trying
Hi I currently have a table view which is being filled via Core Data.
I have 3 tables in my core data tables. Item table : items, which
I have a tableview using NSFetchedResultsController to load data from the Core Data store,
I have a NSFetchedResultsController which displays data in a UITableView. I'm using the boiler
I am having a Core Data problem with NSFetchedResultsController . I have a one
Is it wrong to use an NSFetchedResultsController purely for data management, i.e., without using
I have a list of tasks within Core Data. I fetch them into a
I have a core data application which displays a list of custom objects, each
I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext . I'm using

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.