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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:06:13+00:00 2026-06-09T21:06:13+00:00

I am trying to separate the data into sections by ‘recordDate’ then for each

  • 0

I am trying to separate the data into sections by ‘recordDate’ then for each section the data will be sorted by ‘elementName’ in ascending order. Following is the current code (not working):

NSManagedObjectContext *context = self.tankDatabase.managedObjectContext;
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Log"];
request.sortDescriptors = [NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"recordDate" ascending:NO], [NSSortDescriptor sortDescriptorWithKey:@"elementName" ascending:YES selector:@selector(localizedStandardCompare:)], nil];
request.predicate = [NSPredicate predicateWithFormat:@"ownedBy = %@", self.tank];


self.controller = [[NSFetchedResultsController alloc]
                                          initWithFetchRequest:request
                                          managedObjectContext:context
                                          sectionNameKeyPath:@"recordDate"
                                          cacheName:nil];

self.controller.delegate = self;

NSError *error;
BOOL success = [self.controller performFetch:&error];

However when I tried to use other properties to sort (for example: elementName ASC, value DESC and group them by elementName) it does work as it should. Please note that the recordDate is a ‘Date’ type in data model and NSDate in the class.

Also the recordDate contains minute & seconds where it needs to be grouped to that detail.

I’ve tried to search the entire internet for similar case but I haven’t found any solutions that work. What do I miss in my code? Or is it just an Apple bug? Thank you for your time and assistance.

  • 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-09T21:06:14+00:00Added an answer on June 9, 2026 at 9:06 pm

    I finally figured it out:

    Apparently it’s the sub-seconds information that also being saved into Core Data making the comparison between dates (even though the dates being compared share the exact same date) not working.

    So what I did was to remove the sub-seconds information before saving it to Core Data:

    self.recordDate = [NSDate dateWithTimeIntervalSinceReferenceDate:floor([recordDate timeIntervalSinceReferenceDate])];
    

    I hope this can help anyone facing the same problem. Cheers!

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

Sidebar

Related Questions

I am trying to populate a ListView in a separate class with data taken
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I'm trying to write a library to separate all the disk activity out into
I want to be able to separate the birthday from the mysql data into
I am trying to retrieve two counts from two separate tables into one SQL
I am trying to create a .Net Regex that will separate an Excel header
I am trying to re-load data into the Store which is further used by
I am trying to optimize one part of my code that inserts data into
I'm trying to echo data from an SQLdatabase into a table that is somewhat
I'm trying to create separate data.frame objects based on levels of a factor. So

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.