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

  • Home
  • SEARCH
  • 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 7707061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:15:55+00:00 2026-06-01T00:15:55+00:00

so basically like the title says is there a way to use NSSortDescriptor to

  • 0

so basically like the title says is there a way to use NSSortDescriptor to sort the results of a NSFetchRequest based on a specific attributes (that is a string) length with respect to number of characters?

For example
Order of results would be:

A
AA
AAA
AAAA

and so on

Thanks a lot everyone! I can’t figure this one out

This is the sort descriptor i was trying:

NSSortDescriptor* sort = [NSSortDescriptor sortDescriptorWithKey:@"food_name" ascending:YES comparator:^(id obj1, id obj2) {
    NSInteger len1 = [obj1 length];
    NSInteger len2 = [obj2 length];
    if (len1 < len2) return NSOrderedAscending;
    if (len1 > len2) return NSOrderedDescending;
    return NSOrderedSame;
}];

I put a breakpoint in it and it doesn’t seem to be getting called.

  • 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-01T00:15:56+00:00Added an answer on June 1, 2026 at 12:15 am

    You can write a sort descriptor with a custom comparator. Blocks make it really easy!

    [NSSortDescriptor sortDescriptorWithKey:@"stringName"
     ascending:YES
     comparator:^(id obj1, id obj2) {
        NSInteger len1 = [obj1 length];
        NSInteger len2 = [obj2 length];
        if (len1 < len2) return NSOrderedAscending;
        if (len1 > len2) return NSOrderedDescending;
        return NSOrderedSame;
     }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title description basically says it all. I'd like to use something that requires
Basically, what the title says. I have several properties that combine together to really
Like the title says, my code basically does this: set proxy, test proxy, do
Basically what the title says... I need to have an image that when clicked,
As the title says, is there another way to pass a variable from "current"
Basically, what the title says. I have several properties that combine together to really
My project is basically like a Reddit feed that updates in real-time. I'm trying
I'd basically like to use reflection in Powershell, and after dynamically finding the methods
I am trying to create something in Perl that is basically like the Unix
I've got a socket server running (it's something that's basically like a chat server).

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.