Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort NSMutable array in ascending order

How to sort NSMutable array in ascending order. Can any one help me out this.

like image 800
Malathi Avatar asked Feb 25 '23 07:02

Malathi


2 Answers

You haven't said what's in your array, but if it's something that responds to -compare: then you can use

[myArray sortUsingSelector:@selector(compare):];
like image 135
Lily Ballard Avatar answered Feb 26 '23 20:02

Lily Ballard


Here is a way to sort an array of object

    NSSortDescriptor * descFirstname = [[NSSortDescriptor alloc] initWithKey:@"firstname" ascending:YES];
NSSortDescriptor * descLastname = [[NSSortDescriptor alloc] initWithKey:@"lastname" ascending:YES];
[myArrayOfPerson sortUsingDescriptors:[NSArray arrayWithObjects:descLastname,descFirstname, nil]];
    [descFirstname release];
    [descLastname release];
like image 31
j_freyre Avatar answered Feb 26 '23 20:02

j_freyre