I have an instance array that I will end up changing depending on user settings. I set the to a immutable NSArray:
@property (strong, nonatomic) NSArray *pointArray;
When i need to change the array, i’ve been doing this:
-(void)changePointArray
{
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:self.pointArray];
// Make changes
self.pointArray = [NSArray arrayWithArray:tempArray];
}
Is this acceptable practice or am i creating a leak? Should i just typecast it instead:
self.pointArray = (NSArray *)tempArray;
or do even need to worry about setting a NSMutableArray to a NSArray?
self.pointArray = tempArray;
No, there is no leak (with respect to memory management).
Your code is absolutely ok if your goal is to not expose the mutual array in your public interface.
If, however, you don’t care about abstraction here (or if that property is not public), it would be easier to just declare the property of type
NSMutualArray *in the first place.