Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSMutableArray to NSArray in objective C [duplicate]

Possible Duplicate:
How do I convert NSMutableArray to NSArray?

How can I Convert NSMutableArray to NSArray in Objective C. i.e. without using loop that addObjects one by one.

like image 881
Arsalan Haider Avatar asked Aug 31 '11 09:08

Arsalan Haider


2 Answers

An NSMutableArray is an NSArray already (as it's a subclass of NSArray), but if you really need to create a new immutable instance you can do:

NSArray *myArray = [NSArray arrayWithArray:myMutableArray];
like image 180
Tom Jefferys Avatar answered Oct 11 '22 12:10

Tom Jefferys


How about this code?

NSArray* array = [NSArray arrayWithArray:myMutableArray];
like image 40
Auburg Avatar answered Oct 11 '22 13:10

Auburg