Is the following code doing anything unnecessary?
@interface MyClass {
NSArray *myArray;
}
-(void)replaceArray:(NSArray *)newArray;
@implementation MyClass
-(void)replaceArray:(NSArray *)newArray {
if( myArray )
{
[myArray release];
myArray = nil;
}
myArray = [[NSArray alloc] initWithArray: newArray];
}
@end
What if I made the following changes:
1) Made myArray a property:
@property (nonatomic, retain) NSArray myArray;
2) Changed the assignment to:
self.myArray = [NSArray arrayWithArray: newArray];
Would that allow me to remove the conditional?