As above. Would be helpful to know. Thanks!
Asked
Active
Viewed 5.1k times
31
-
9adding "need this urgently" is likely to have the opposite effect... – Mitch Wheat Jul 11 '10 at 06:40
-
This is like the third exact question on NSArray and NSMutableArray's today. – Anurag Jul 11 '10 at 07:10
3 Answers
85
Here are two options:
- (NSMutableArray *)createMutableArray1:(NSArray *)array
{
return [NSMutableArray arrayWithArray:array];
}
- (NSMutableArray *)createMutableArray2:(NSArray *)array
{
return [[array mutableCopy] autorelease];
}

Cameron Spickert
- 5,190
- 1
- 27
- 34
-
2Here's a conversion back to an NSArray: NSArray *array = [NSArray arrayWithArray:mutableArray]; – Nick N Sep 05 '14 at 22:52
18
Use -mutableCopy
and make sure to balance the retain count.
NSMutableArray *mutableArray = [[immutableArray mutableCopy] autorelease];

Fabian Kreiser
- 8,307
- 1
- 34
- 60
-
3It's now: NSMutableArray *mutableArray = [immutableArray mutableCopy]; – Marcel Marino Jun 18 '15 at 15:54
-