3

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?

0

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.