Here is my NSArray
myArray = [NSArray arrayWithObjects: @"a", @"b", @"c", @"d", @"e", nil];
Now I’m looping through the array like this:
int size = [myArray count];
NSLog(@"there are %d objects in the myArray", size);
for(int i = 1; i <= size; i++) {
NSString * buttonTitle = [myArray objectAtIndex:i];
// This gives me the order a, b, c, d, e
// but I'm looking to sort the array to get this order
// e,d,c,b,a
// Other operation use the i int value so i-- doesn't fit my needs
}
In the for loop this gives me the order:
a, b, c, d, e
but I’m looking to sort the array to get this order:
e, d, c, b, a
Any thoughts?
I need to keep the array in the original sort order as well.
Try calling
reverseObjectEnumeratoron the array and using a for-in loop to cycle through the objects:This will output:
Alternatively, you can reverse the array in place if you’d like to iterate through the array by index or do something else with it: