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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:09:31+00:00 2026-06-18T06:09:31+00:00

Hi I have following issue: I’m programming a game and everytime the player finishes

  • 0

Hi I have following issue:

I’m programming a game and everytime the player finishes a score is submitted. So i got two Datasources: Score and Mode. And i want to sort these Highscores in 4 sections, the 4 modes i have. And in these sections it should be sorted by Score (highest on the top).

Yet I got this code:

- (NSFetchedResultsController *)fetchedResultsController{
if (_fetchedResultsController != nil) {
    return _fetchedResultsController;
}

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Set the batch size to a suitable number.
[fetchRequest setFetchBatchSize:20];

// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"score" ascending:NO];
NSArray *sortDescriptors = @[sortDescriptor];

[fetchRequest setSortDescriptors:sortDescriptors];

// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"mode" cacheName:nil];
_fetchedResultsController.delegate = self;
[_fetchedResultsController performFetch:nil];

NSError *error = nil;
if (![self.fetchedResultsController performFetch:&error]) {
     // Replace this implementation with code to handle the error appropriately.
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return _fetchedResultsController;}

But all I get is a pretty random Sorting. The first time it worked but after a few games it messed up!
My modes are: 10,20,30,60 (seconds) The golden badge on the left shows what section it should be sorted in.
Hope someone can help me.

iPhone Screenshot

  • 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-18T06:09:32+00:00Added an answer on June 18, 2026 at 6:09 am

    You need to add another sort descriptor for mode as well as for score.

    You need to sort first by mode and then by score. As you are currently sorting by score and sectioning by name you’ll get…

    Mode 1:
    - Score 100
    - Score 99
    Mode 2:
    - Score 80
    Mode 1:
    - Score 70
    etc...
    

    Change your sort descriptor code like this…

    NSSortDescriptor *modeSD = [[NSSortDescriptor alloc] initWithKey:@"mode" ascending:YES];
    NSSortDescriptor *scoreSD = [[NSSortDescriptor alloc] initWithKey:@"score" ascending:NO];
    NSArray *sortDescriptors = @[modeSD, scoreSD];
    
    [fetchRequest setSortDescriptors:sortDescriptors];
    

    That should sort it for you (pun very much intended 😉 )

    If you would like four separate sections then your NSFRC will look like this…

    // note the section name key path
    NSFetchedResultsController *nsfrc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"mode" cacheName:nil];
    

    This will then split the data into sections and rows.

    Count of sections is [[nsfrc allSections] count];

    And so on…

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

Sidebar

Related Questions

I have the following issue: A java object contains two arrays of core datastore
I have got the following issue, my function appends code to a string $string
I have the following issue: I need to mix respectively two lists in python...
I have following issue: I got an event listener on an input field. On
I have the following issue. I have two classes that manipulate information but they
I have the following issue: I have two projects: jre1.7 and android 2.1. I'd
I have the following issue related to iterating over an associative array of strings
I have the following issue and I would like to know what exactly happens.
I have the following issue with a UTF8 files structured as following: FIELD1§FIELD2§FIELD3§FIELD4 Looking
I have the following issue: I have a splash like window coming with my

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.