Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inverse the contents of NSArray in Objective-C?

How do i inverse the contents of NSArray in Objective-C?

Assume that i have an array which holds these data

NSArray arrayObj = [[NSArray alloc]init];
arrayObj atindex 0 holds this: "1972"
arrayObj atindex 1 holds this: "2005"
arrayObj atindex 2 holds this: "2006"
arrayObj atindex 3 holds this: "2007"

Now i want to inverse the order of array like this:

arrayObj atindex 0 holds this: "2007"
arrayObj atindex 1 holds this: "2006"
arrayObj atindex 2 holds this: "2005"
arrayObj atindex 3 holds this: "1972"

How to achive this??

Thank You.

like image 541
suse Avatar asked Nov 27 '22 03:11

suse


1 Answers

NSArray* reversed = [[originalArray reverseObjectEnumerator] allObjects];
like image 121
ig2r Avatar answered Jan 13 '23 14:01

ig2r