Thursday, May 26, 2011

Reverse an array in iPhone SDK

Hello Friends,

We some times need to reverse an array in some cases for such issues there is no ready made function to reverse an array in iPhone SDK.

Solution of this problem can be solved by following function.

- (NSMutableArray *)reverseArray:(NSMutableArray *)arr{
NSUInteger i = 0;
NSUInteger j = [arr count] - 1;
while (i < j) {
[arr exchangeObjectAtIndex:i withObjectAtIndex:j];
i++;
j--;
}
 return arr;
}
Above function will return same array with reverse value.

No comments:

Post a Comment