1
votes

I have an interface

@interface A 
{
    NSMutableArray *_myArray;
} 

@property(nonatomic, retain)NSMutableArray *myArray;

In in the implementation I have written

@synthesize myArray = _myArray;

And in the body of the code where I am using this array is only storing some arrays values which is like this...

-(void)updateArray:(NSArray*)p_NewValues
{
    self.myArray = nil;
    myArray = [NSMutableArray alloc]initwithArray:p_NewArray];
}

but unfortunate in code review I found that I don't required any variable definition only Synthesize is OK, can anybody explain why?

2
Even these are not required "NSMutableArray *_myArray;" and @synthesize myArray = _myArray;Anoop Vaidya

2 Answers

3
votes

From documentation

The @synthesize directive also synthesizes an appropriate instance variable if it is not otherwise declared.

3
votes

With the modern Objective-C compiler used in the latest versions of Xcode, you don't need an explicit ivar nor do you even need the @synthesize anymore. Your code can now be:

@interface A

@property (nonatomic, retain) NSMutableArray *myArray;

@end

@implementation A

- (void)updateArray:(NSArray *)p_NewValues {
    self.myArray = [NSMutableArray arrayWithArray:p_NewArray];
}

@end