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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:50:59+00:00 2026-06-06T15:50:59+00:00

I use this a lot NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES comparator:^(id obj1, id

  • 0

I use this a lot

NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil 
                       ascending:YES 
                       comparator:^(id obj1, id obj2) {
                       return [obj1 compare:obj2 options:NSNumericSearch];
                       }];

I would like to create a compiler define like this

#define descriptor [NSSortDescriptor sortDescriptorWithKey:nil 
                       ascending:YES 
                       comparator:^(id obj1, id obj2) {
                       return [obj1 compare:obj2 options:NSNumericSearch];
                      }]

so I can use it on all parts of my code without having to declare it all times and use it on stuff like

mySortedArray = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];

. I have tried this and received a ton of errors from Xcode. Is there a way to define that?

thanks

  • 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-06T15:51:00+00:00Added an answer on June 6, 2026 at 3:51 pm

    You were almost there:

    #define descriptor [NSSortDescriptor sortDescriptorWithKey:nil \
                                                     ascending:YES \
                                                    comparator:^(id obj1, id obj2) { \
                                          return [obj1 compare:obj2 options:NSNumericSearch];}]
    

    Then:

    NSArray *sorted = [myArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
    

    The reason you get errors is because you should use \ when going to a new line. Also -sortedArrayUsingDescriptors requires an array…

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

Sidebar

Related Questions

use this website a lot but first time posting. My program creates a number
Similar, but different to this question : I use highlight occurrences a lot, but
i use this code in my app. just found is not correct when compare
I've never programmed using C or whatever but I use this site a lot
It seems a lot of libraries/plugins use this syntax: def self.included(base) # :nodoc: base.extend
I tend to use this a lot, but it's ugly: a = (lambda x:
this is my first question, but i use this site a lot this last
I use this function a lot in game/graphics programming. float slide(float from, float to,
Can anybody tell me why a lot of Ruby boolean methods use this double
I happen to use this kind of structure quite a lot: Dictionary<string, List<string>> Foo

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.