Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse NSMutableArray

What is the best/correct way to reverse an NSMutableArray?

like image 901
some_id Avatar asked Feb 28 '11 00:02

some_id


People also ask

How do you reverse an NSArray?

You can reverse a NSArray by writing your own loop iterating from the end towards the beginning and using a second array to add the items in reverse order. Or you can simply use - (NSEnumerator *)reverseObjectEnumerator from the NSArray class.

What is difference between NSArray and NSMutableArray?

The primary difference between NSArray and NSMutableArray is that a mutable array can be changed/modified after it has been allocated and initialized, whereas an immutable array, NSArray , cannot.

What is NSMutableArray?

The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .


1 Answers

themutablearray=[[[themutablearray reverseObjectEnumerator] allObjects] mutableCopy]; 
like image 163
Ajay Avatar answered Oct 19 '22 09:10

Ajay