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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:42:20+00:00 2026-05-13T10:42:20+00:00

I have an NSArray containing numbers as NSString objects. ie. [array addObject:[NSString stringWithFormat:@%d, 100]];

  • 0

I have an NSArray containing numbers as NSString objects. ie.

[array addObject:[NSString stringWithFormat:@"%d", 100]];

How do I sort the array numerically? Can I use compare:options and specify NSNumericSearch as NSStringCompareOptions? Please give me an example/sample code.

  • 1 1 Answer
  • 1 View
  • 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-13T10:42:20+00:00Added an answer on May 13, 2026 at 10:42 am

    You can use the example code given for the sortedArrayUsingFunction:context: method which should work fine for NSStrings too as they also have the intValue method.

    // Place this functions somewhere above @implementation
    static NSInteger intSort(id num1, id num2, void *context)
    {
        int v1 = [num1 intValue];
        int v2 = [num2 intValue];
        if (v1 < v2)
            return NSOrderedAscending;
        else if (v1 > v2)
            return NSOrderedDescending;
        else
            return NSOrderedSame;
    }
    
    // And used like this
    NSArray *sortedArray; 
    sortedArray = [anArray sortedArrayUsingFunction:intSort context:NULL];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have an NSArray containing NSString. How can I convert the NSArray to
I have a large NSArray containing NSNumbers like 3, 4, 20, 10, 1, 100,
I have a problem with sorting... I need to sort NSArray containing NSDictionaries .
i have an NSArray which contains custom objects, the objects have an NSString property,
I have a 1D numpy array containing complex numbers (eg. numpy.complex64). I need to
I have an NSArray with objects : NSArray *array = [NSArray arrayWithObjects:@Saturday,@Sunday,@Monday,@tuesday,@Wednesday,@thursday,nil]; and some
I have a NSArray containing objects. I want to create a secondary NSArray containing
I have an NSArray containing custom objects, for example: [A, A, B, C, A,
I have an NSArray containing several NSDictionaries . I have an NSString containing an
Another puzzler. I have an NSArray (iTours) containing 3 Objects and a retain count

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.