Reputation: 4885
When manually implementing @property instead of using @synthesize, do you have to include ARC code?
Would it be ok to implement it like this:
@synthesize var1;
- (void)setvar1:(NSObject *)newVar1
{
var1 = newVar1;
}
or do you have to include retain
, release
etc?
Upvotes: 3
Views: 177
Reputation: 726479
What you call "ARC code" (retain
, release
, etc.) is actually manual reference counting, not automatic.
If you are compiling with no ARC, you need to retain
or copy the object as required. If you are under ARC, the compiler will take care of it for you. Specifically, the compiler will retain newVar1
if var1
is declared __strong
.
Upvotes: 1
Reputation: 992747
When using ARC, you cannot write code that manually uses retain
, release
, and so on. Therefore, if you choose to implement your property getters and setters manually, and you have ARC enabled, you don't have to include that extra memory management code.
Upvotes: 1
Reputation: 60110
Under ARC, you don't have to (and in fact cannot) manually retain
or release
variables. Your implementation, apart from needing a capital V in setVar1:
, is perfectly acceptable under ARC.
Upvotes: 2