Objective-c – How to convert NSMutableArray to NSArray

cocoacocoa-touchnsarraynsmutablearrayobjective c

How do I convert NSMutableArray to NSArray in ?

Best Answer

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.