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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:49:32+00:00 2026-05-14T04:49:32+00:00

In my NSFetchedResultsController, I set a sortDescriptor that sorts based on the date property

  • 0

In my NSFetchedResultsController, I set a sortDescriptor that sorts based on the date property of my managed objects. The problem that I have encountered (along with several others according to Google) is that nil values are sorted at the earliest end rather than the latest end of the date spectrum. I want my list to be sorted earliest, earlier, now, later, latest, nil. As I understand it, this sorting is done at the database level in SQLite and so I cannot construct my own compare: method to provide the sorting I want.

I don’t want to manually sort in memory, because I would have to give up all of the benefits of NSFetchedResultsController. I can’t do compound sorting because the sectionNameKeyPaths are tightly coupled to the date ranges. I could write a routine that redirects indexPath requests so that section 0 in the results controller gets mapped to the last section of the tableView, but I fear that would add a lot of overhead, severely increase the complexity of my code, and be very, very error-prone.

The latest idea that I am considering is to map all nil dates to the furthest future date that NSDate supports. My left brain hates this idea, as it feels more like a hack. It will also take a bit of work to implement, since checking for nil factors heavily into how I process dates in my app. I don’t want to go this route without first checking for better options. Can anyone think of a better way to get around this problem?

Update

A possible better way to get around this problem would be to switch to a binary persistent store. From what I have read in the documentation, sorting is done in Objective-C with the binary persistent store, so I could supply my own compare method for the date sorting. I have two concerns with this approach. First, what kind of performance hit am I going to see by moving to a binary store? Second, how difficult is it going to be to roll out this change in an app update?

  • 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-14T04:49:33+00:00Added an answer on May 14, 2026 at 4:49 am

    I decided to go with the “hack” fix, because I didn’t want to incur the overhead of having the entire object graph loaded in memory that comes with using the binary store. Instead of storing nil when the user doesn’t set a date, I store the result of a “noDate” class method.

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

Sidebar

Related Questions

I have a table view that is managed by an NSFetchedResultsController. I am having
I have a list of objects in a UITableView , managed by a NSFetchedResultsController
I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext . These objects
I am using an NSFetchedResultsController to manage displaying fetched managed objects in a table
I have a UITableView based on a NSFetchedResultsController . To insert a new row
I have a tableview that is successfully incorporating an NSFetchedResultsController. However, I need the
I recently encountered some problems while trying to sort a set of objects. The
I have these objects that are unique except for two columns once of which
I have a UISearchBar that is hooked up with a NSFetchedResultsController . It searches
I have an NSFetchedResultsController displaying places in a table view, but when I update

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.