I have a array inside my init method and then I wish to make a mutable array inside if condition when it's actually needed. Is it possible?
Presently am doing:
- (id)init
{
self = [super init];
if (self)
{
// [MyClass someMethod] in the below statement returns an array.
NSMutableArray *someArray = [NSMutableArray arrayWithArray:[MyClass someMethod]];
if (this condition is true)
{
[someArray addObject:@"XYZ"];
}
// Print someArray here.
}
}
What I am trying to do it:
- (id)init
{
self = [super init];
if (self)
{
// [MyClass someMethod] in the below statement returns an array.
NSArray *someArray = @[[MyClass someMethod]];
if (this condition is true)
{
// Make some array mutable here and then add an object to it.
[someArray mutableCopy];
[someArray addObject:@"XYZ"];
}
// Print someArray here.
}
}
Am I doing it right? Or is what I am thinking possible? Can I make the same array mutable whenever needed as in my case I need it to be mutable only if my condition in if is true.