8

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.

Community
  • 1
  • 1
Arsalan Haider
  • 559
  • 3
  • 9
  • 23

2 Answers2

15

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];
Tom Jefferys
  • 13,090
  • 2
  • 35
  • 36
4

How about this code?

NSArray* array = [NSArray arrayWithArray:myMutableArray];
Emil
  • 7,220
  • 17
  • 76
  • 135
Auburg
  • 155
  • 1
  • 2
  • 6