Pages

Saturday, April 23, 2011

Iphone: reverse an array

In iphone sdk no way to reverse an array.

So to solve this problem, we just implement the small function.

Like below: use as it is.

- (NSMutableArray *)reverseArray:(NSMutableArray *)arr{
NSUInteger i = 0;
NSUInteger j = [arr count] - 1;
while (i < j) {
[arr exchangeObjectAtIndex:i withObjectAtIndex:j];
i++;
j--;
}
 return arr;
}

that retain you array with reverse value.

No comments:

Post a Comment