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

The Archive Base Latest Questions

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

I have a Word : NSManagedObject subclass that I’m trying to group by the

  • 0

I have a Word : NSManagedObject subclass that I’m trying to group by the first letter of the word. In each section I’m then trying to sort by the length property while maintain the alphanumeric sort when words have the same length. So it would appear like

A Words

  • apple Length = 5
  • axe Length = 3
  • am Length = 2

B Words

  • bane Length = 4
  • boat Length = 4
  • bag Length = 3

So I init a new NSFetchRequest first. Then I add my sort descriptors, first sorting by the value (which is just the word), then sorting by the length. Finally init my fetchedResultsController and using the group value to group them by the first letter.
Here is my code but I’m not getting the desired result. Any help would be greatly appreciated.

@interface Word : NSManagedObject

@property (nonatomic, retain) NSString * value;
@property (nonatomic, retain) NSString * group;
@property (nonatomic, retain) NSNumber * length;

@end

NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Word"];
request.sortDescriptors = [NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"value" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)],
                               [NSSortDescriptor sortDescriptorWithKey:@"length" ascending:NO], nil];

self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.wordDatabase.managedObjectContext
                                                                          sectionNameKeyPath:@"group"
                                                                                   cacheName:nil];
  • 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-18T00:09:44+00:00Added an answer on June 18, 2026 at 12:09 am

    The first sort descriptor should be for the key used as sectionNameKeyPath, the second sort descriptor for the key length and the last one for value:

    request.sortDescriptors = [NSArray arrayWithObjects:
        [NSSortDescriptor sortDescriptorWithKey:@"group" ascending:YES],
        [NSSortDescriptor sortDescriptorWithKey:@"length" ascending:NO],
        [NSSortDescriptor sortDescriptorWithKey:@"value" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)],
        nil];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Word document with macros that I am trying to open in
I have a NSString [WORD] that has some length [LEN]. What i need to
I have a word document that was saved as xml. now I need to
I have Microsoft Word template that I automated filling it's fields from my application,
I have a VBA Word Macro that gets words from .txt list and color
After trying to figure how to have an effective word counter of a string,
I have MS Word files that have a header with 2 Text Boxes and
I have an word file that contain my specified pattern text {pattern} and I
I have Word survey files, each containing forms filled by subjects. Until now I
I have a string like 23ert[word]45y[li]dfdf[beautiful]adf . I want to collect each word surrounded

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.