Here is an example of reversing a NSArray/NSMutableArray
NSString *string = @"a,b,c,d,e,f,g,h,i,j,k";
NSArray *array = [string componentsSeparatedByString:@","];
NSLog(@"array = %@",array);
NSArray* reversedArray = [[array reverseObjectEnumerator] allObjects];
NSLog(@"Reverse array = %@",reversedArray);
Happy coding all iPhone coderz
4 comments:
You cant use this with NSMutableArray!
NSArray and NSMutableArray are different.
@Anonymous: NSMutableArray is a subclass of NSArray, so it works with both. In both cases it creates a new array and does not affect the original.
Tried reversing an array of dictionaries, and it creates a reversed array of arrays
For NSMutableArray.
NSArray*Arry=[[self.xAxisArrayForPlot reverseObjectEnumerator]allObjects];
NSMutableArray *xAxesArray = [NSMutableArray arrayWithArray:Arry];
Post a Comment