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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:59:09+00:00 2026-06-16T07:59:09+00:00

I want to sort NSMutableArray which have NSInteger values inside. I tried to use

  • 0

I want to sort NSMutableArray which have NSInteger values inside. I tried to use this solution:

 NSArray *sorted = [array sortedArrayUsingSelector:@selector(compare:)];

It almost worked, so i want to ask why not everything alright with it. Here is example of data:

not sorted = (
    30,
    42,
    54,
    6,
    18
)

 sorted = (
    18,
    30,
    42,
    54,
    6
)

We can see that it sorted everything but 6 value which is at the end off array.

Why this could happened ?

Thank you.

Full method:

- (void) initialize{
    NSInteger min = 30;
    NSInteger interval = 12;
    NSInteger count = floor(60/interval);

    for (int i = 0; i < count; i++) {

        [array addObject:[NSString stringWithFormat:@"%i",min]];
        min +=interval;

        if (min > 60)
            min -= 60;
    }

    //DLog(@"not sorted = %@",minutes);
    array = [[array sortedArrayUsingSelector:@selector(compare:)] mutableCopy];
    //DLog(@"sorted = %@",minutes);

}
  • 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-16T07:59:10+00:00Added an answer on June 16, 2026 at 7:59 am

    You are getting problem in above case because you are sorting string values not a NSNUMBER.
    You have to use NSNumber to add objects of integer. Then do something like:

          NSMutableArray *array = [[NSMutableArray alloc ] initWithObjects:
                                  [NSNumber numberWithInt:10],    
                                  [NSNumber numberWithInt:50],
                                  [NSNumber numberWithInt:5],
                                  [NSNumber numberWithInt:3],
                                  nil];
    
          NSLog(@"SORTED = %@",[array sortedArrayUsingSelector:@selector(compare:
                                                                   )]);
    

    This will give you a sorted array.

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

Sidebar

Related Questions

I have NSMutableArray* names , which contains NSStrings. I want to sort the array
I have an NSArray of strings that I want to use as my sort
I want to sort a NSMutableArray which has NSArrays with respect to the value
If I want to return an immutable array like this + (NSArray *)ids but
I want to sort my array.... In my array elements are in this order
I have a NSMutableArray with NSStrings and I want to sort them in alphabetical
I have an nsmutablearray named nsmarrMedicineInfo. I want to sort the element by using
I have a array NSMutableArray with Values say 10, 2, 13, 4. Also there
i have NSMutableArray contains NSArray Objects, it looks like this ( 2012-10-10 13:13:29 +0000,
How to sort this kind of case? I have a NSMutableArray . My NSMutableArray

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.