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

The Archive Base Latest Questions

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

situation: CoreData db with contacts entities and Sum attribute (positive or negative or 0)

  • 0

situation: CoreData db with “contacts” entities and “Sum” attribute (positive or negative or 0)

goal: tableviewcontroller with 3 sections, 1st positive 2nd negative 3rd (zero) “ARCHIVED”

so far: sort descrpitor with @selector(compare:) (without predicate because list of all contacts wanted)

NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Contact"];

request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"moneySum" ascending:YES selector:@selector(compare:)]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                    managedObjectContext:self.database.managedObjectContext
                                                                      sectionNameKeyPath:@"sectionName"
                                                                               cacheName:nil];

and in a Category for Contact Entity:

- (NSString *)sectionName {

    [self willAccessValueForKey:@"sectionName"];
    NSString *sectionName;
    double value = [[self valueForKey:@"moneySum"] doubleValue];

    if      (value > 0) sectionName = POS_SECTION;
    else if (value < 0) sectionName = NEG_SECTION;
    else                sectionName = ARCHIVE_SECTION;

    [self didAccessValueForKey:@"sectionName"];
    return sectionName;
}

I do get 3 categories now, but it obviously sorts them with archive in the middle, not at the end.

I thought about adding a second sortDescriptor to the sortDescriptors array (before compare: one) but the most intuitive way for me (isEqualToNumber:) obviously doesn’t work because i can’t specify any arguments (@selector ( ..:) ) or am I wrong?

Sorry, quite new to this whole coding thing 🙂

  • 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:05:57+00:00Added an answer on June 9, 2026 at 9:05 pm

    From the “Core Data Programming Guide”:

    … To summarize, though, if you execute a fetch directly, you should
    typically not add Objective-C-based predicates or sort descriptors to
    the fetch request. Instead you should apply these to the results of
    the fetch.

    This means that you cannot use a custom sort descriptor in your fetch request. You must store an additional (non-transient) attribute in the entity, for example “0”, “1”, “2” for positive/negative/zero sums.

    You can then use this attribute for both the sort descriptor and for the sectionNameKeyPath, you don’t need a transient attribute “sectionName”.

    The mapping from “0”, “1”, “2” to the actual section header is then done in tableView:titleForHeaderInSection:.

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
        id <NSFetchedResultsSectionInfo> sectionInfo = [[self.controller sections] objectAtIndex:section];
        int order = [[sectionInfo name] intValue];
        if (order == 0)
            return @"POSITIVE SECTION";
        else if (order == 1)
            return @"NEGATIVE SECTION";
        else
            return @"ARCHIVE SECTION";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the abstract situation: I have CoreData objects 'car' and 'review'.'review' can be 'good','bad'
Situation: I have user model. attribute meta_data in db represents text type field. In
I have a situation where I want to pre populate a CoreData DB with
CoreData and ResultsController make the job really easy. But... Here is the situation: I
The situation: I fetch a complete table from my sqllite core data database and
Situation is simple: I post a plain HTML form with a textarea. Then, in
Situation: I'm working with Adobe Livecycle ES2 and Flex In our project we show
Situation: 1. Linux TCP server 2 Windows C# client application The server receives messages
Situation: I have an index page which loads pages into it with ajax as
Situation: I often run into this problematic and never know how to solve it.

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.