"Reverse" NSMutableArray's elements order [duplicate]
Possible Duplicate:
How can I reverse a NSArray in Objective-C?
Is there a way to reverse the elements in a NSMutableArray?
How can I reverse a NSArray in Objective-C?
I don't think that there is an easy way to do it. Best way that I came up with is the exchangeObjectAtIndex:withObjectAtIndex: function.
pseudo code:
NSMutableArray* array = [NSMutableArray arrayWithObjects:@"1", @"2", @"3",nil];
for(i = 0, len = (int)[array count]/2; i < len; i++)
{
[array exchangeObjectAtIndex:i withObjectAtIndex:([array count] - i - 1)];
}
Don't have the compiler open right at this moment but hopefully this does the trick.
精彩评论