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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:14:43+00:00 2026-06-19T00:14:43+00:00

See also Core Data Sort By Date With FetchedResultsController into sections Is there a

  • 0

See also

Core Data Sort By Date With FetchedResultsController into sections

Is there a way to group objects from a CoreData entity by date and use them to create multiple sections on a UITableView control?

Essentially, I need something equivalent to the following pseudo-SQL, where my_group_criteria() groups all tests by day:

SELECT * FROM tests GROUP BY my_group_criteria(date)

As an example, the query would group the following rows into 3 separate sections:

[test1 | 2013-03-18 15.30.22]
[test2 | 2013-03-18 14.30.22]
[test3 | 2013-03-18 13.30.22]

[test4 | 2013-03-17 18.30.22]
[test5 | 2013-03-17 19.30.22]

[test6 | 2013-03-15 20.30.22]

As already answered in 2, NSPredicate is not for grouping entities so this may not be the way to go.

Given this, how do I go about creating multiple sections in a UITableView based on some criteria similar to what SQL GROUP BY would do?

I would like to avoid accessing the SQL-lite database directly if at all possible.

Related question 1:
NSPredicate: filtering objects by day of NSDate property

Related question 2:
NSPredicate something equivalent of SQL’s GROUP BY

  • 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-19T00:14:44+00:00Added an answer on June 19, 2026 at 12:14 am

    You can modify the DateSectionTitles sample project from the Apple Developer Library according to you needs.

    First, you have to modify the accessor function for the transient sectionIdentifier property to create a section identifier based on year+month+day (instead of year+month only):

    - (NSString *)sectionIdentifier {
    
        // Create and cache the section identifier on demand.
    
        [self willAccessValueForKey:@"sectionIdentifier"];
        NSString *tmp = [self primitiveSectionIdentifier];
        [self didAccessValueForKey:@"sectionIdentifier"];
    
        if (!tmp) {
            /*
             Sections are organized by month and year. Create the section identifier
             as a string representing the number (year * 10000 + month * 100 + day);
             this way they will be correctly ordered chronologically regardless of
             the actual name of the month.
             */
            NSCalendar *calendar = [NSCalendar currentCalendar];
    
            NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
                                   fromDate:[self timeStamp]];
            tmp = [NSString stringWithFormat:@"%d", [components year] * 10000 + [components month] * 100  + [components day]];
            [self setPrimitiveSectionIdentifier:tmp];
        }
        return tmp;
    }
    

    Second, the titleForHeaderInSection delegate method must be changed, but the idea is the same: extract year, month and day from the section identifer, and create a header title string from that:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    
        id <NSFetchedResultsSectionInfo> theSection = [[fetchedResultsController sections] objectAtIndex:section];
    
        NSInteger numericSection = [[theSection name] integerValue];
        NSInteger year = numericSection / 10000;
        NSInteger month = (numericSection / 100) % 100;
        NSInteger day = numericSection % 100;
    
        // Create header title YYYY-MM-DD (as an example):
        NSString *titleString = [NSString stringWithFormat:@"%d-%d-%d", year, month, day];
        return titleString;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help in using objects from Core Data with GCD; I seem
see also Differences between LINQ to Objects and LINQ to SQL queries We are
When we create core data object automatically I see a line @synthesize managedObjectContext=__managedObjectContext; However,
I've been looking into some tutorials on using Core Data, and I've seen consists
I have a window with a list full of Core Data objects, and a
I have a results array containing the fetch results from core data. It is
I am trying to import a set of data into a CoreData persistentStore. This
We're performing our first iOS app update, and also our first Core Data migration.
See also SO 1664677 I get this error 2: Syntax error: ( unexpected when
See also: Emacs behind HTTP proxy Is it possible to tell emacs to automatically

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.