How do I convert NSMutableArray to NSArray?

marcy picture marcy · Nov 20, 2009 · Viewed 197.9k times · Source

How do I convert NSMutableArray to NSArray in ?

Answer

Georg Schölly picture Georg Schölly · Nov 20, 2009
NSArray *array = [mutableArray copy];

Copy makes immutable copies. This is quite useful because Apple can make various optimizations. For example sending copy to a immutable array only retains the object and returns self.

If you don't use garbage collection or ARC remember that -copy retains the object.