Converting NSArray to NSMutableArray
51,062
Solution 1
Here are two options:
- (NSMutableArray *)createMutableArray1:(NSArray *)array
{
return [NSMutableArray arrayWithArray:array];
}
- (NSMutableArray *)createMutableArray2:(NSArray *)array
{
return [[array mutableCopy] autorelease];
}
Solution 2
Use -mutableCopy
and make sure to balance the retain count.
NSMutableArray *mutableArray = [[immutableArray mutableCopy] autorelease];
Solution 3
Try this one
NSMutableArray *array = [[NSMutableArray alloc]initWithArray:your_array_name];
Author by
Sidwyn Koh
Updated on April 29, 2020Comments
-
Sidwyn Koh about 4 years
As above. Would be helpful to know. Thanks!