Does different iVar name change retain count when used with property
Posted
by
russell
on Stack Overflow
See other posts from Stack Overflow
or by russell
Published on 2012-09-19T09:30:55Z
Indexed on
2012/09/19
9:37 UTC
Read the original article
Hit count: 331
objective-c
|cocoa-touch
Here is 2 code snapshot-
Class A:NSObject
{
NSMutableArray *a;
}
@property (retain) NSMutableArray *a;
@implementation
@synthesize a;
-(id)init
{
if(self=[super init])
{
a=[[NSMutableArray alloc] init];
}
}
@end
Class A:NSObject
{
NSMutableArray *_a;
}
@property (retain) NSMutableArray *a;
@implementation
@synthesize a=_a;
-(id)init
{
if(self=[super init])
{
_a=[[NSMutableArray alloc] init];
}
}
@end
Now what i need to know, is in both code instance variable assigned value directly rather than using accessor and retain count is 1? Or there is difference between them. Thanks.
And one more things, apple recommended not to use accessor in init/dealloc, but at the same time ask not to directly set iVar. So what is the best way to assign value of ivar in init()??
© Stack Overflow or respective owner