I have an NSArray of NSNumber objects that I have successfully sorted in ascending order using the following:
[myArray sortedArrayU
we can do it simply by using sortUsingSelector. The code as follows;
NSMutableArray *arr=[[NSMutableArray alloc]initWithObjects: ..objects.. ];
//Can also use NSArray.
[arr sortUsingSelector:@selector(compare:options:)];
NSString *temp;
int i,j;
i=0;
j=[arr count];
for(i=0;i<([arr count]-1);i++)
{
temp=[arr objectAtIndex:i];
[arr replaceObjectAtIndex:i withObject:[arr objectAtIndex:j]];
[arr replaceObjectAtIndex:j withObject:temp];
j--;
}
NSLog(@"New array is:%@",arr);
You may think that WHAT A STUPID ANSWER it is :D :D Actually, am not teasing anyone. But in simple logic, we can sort array in descending order by this way. No need of using any type of descriptors or any other complicated stuffs. And it will be easier for entry level programmers.