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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:04:48+00:00 2026-05-28T11:04:48+00:00

How can I index a NSFetchedResultsController so that I can implement an A-Z index

  • 0

How can I index a NSFetchedResultsController so that I can implement an A-Z index on a tableview.

I see in the initializer I can do sectionNameKeyPath but this just places unique objects in their own section.

Here is what I have for my NSFetchedResultsController

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

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Customer" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    [fetchRequest setFetchBatchSize:20];

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
    NSArray *sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil];

    [fetchRequest setSortDescriptors:sortDescriptors];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"name" cacheName:@"Customer"];
    aFetchedResultsController.delegate = self;

    self.fetchedResultsController = aFetchedResultsController;

    return __fetchedResultsController;
}  
  • 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-28T11:04:49+00:00Added an answer on May 28, 2026 at 11:04 am

    implement sectionIndexTitlesForTableView: like this:

    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
        return [self.fetchedResultsController sectionIndexTitles];
    }
    

    this will give you those indexes on the right side of the tableView.

    If you want your sections to have names like A, B, C, D etc. you have to implement a method that returns the first letter for your object.

    something like this:

    - (NSString *)firstLetter {
        [self willAccessValueForKey:@"firstLetter"];
        NSString *firstLetter = [[[self name] substringToIndex:1] uppercaseString];
        [self didAccessValueForKey:@"firstLetter"];
        return firstLetter;
    }
    

    This goes into the custom subClass of your coredata entity.

    Then add a transient attribute named firstLetter to your core data entity and replace the sectionNameKeyPath in the NSFetchedResultsController init with firstLetter

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

Sidebar

Related Questions

If this is possible, one can index into a variadic template parameter pack without
Mongo docs state: The Mongo multikey feature can automatically index arrays of values. That's
how can i redirect index.php?search= to the base url? I tried it with this
I know that I can return the index of a particular character of a
Is there any plugin for VIM that I can use to index an C++
What tools are out on the market that can index documents and text? Ideally
Today I heard from my colleague that search bot can index pages with sequential
I'm trying to create a custom deployer in Tridion 2011 SP1 that can index
How should one place links in a Flash app such that google can index
i have ListBox on my xaml page called MainListBox. i can get index that

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.