Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change with properties and ivars after ARC migration

I have used the "Convert to Objective C ARC" option in Xcode 4.3 to convert a project started in Xcode 4.0 to use ARC. After fixing errors that the tool found, I went trough the process where the migration tool has removed all the release messages as well as retain attributes in my properties declarations. So now I have all of my properties having only (nonatomic) attribute. From reading the documentation I still don't have a clear answer on what to do.

So my question is: In case you omit the keyword regarding the setter semantics (strong, weak, retain, assign) in the property declaration, what is the default attribute on properties when using ARC?

I found in the documentation that the default property attribute is assign. However, they also say that now the default attribute for ivars, in case you omit it, is strong.

To better explain my question, here is an example. I header file we have the declaration:

@property (nonatomic) MyClass *objectToUse;

and in our implementation we just have

@synthesize objectToUse;

If we then write inside some method:

self.objectToUse = [[MyClass alloc] init];

have we created an strong (retain) or weak (assign) reference? If we instead write

objectToUse = [[MyClass alloc] init];

by using the ivar have we changed the situation regarding the object retention policy? It seems to me that now with ARC, the best practice of using the properties for memory management is not the same practice anymore.

like image 524
lgdev Avatar asked Mar 06 '12 11:03

lgdev


1 Answers

I've opened an Technical Support Incident. The engineer verified that the default was changed from "assign" to "strong". The reason is exactly the inconsistency you described. Now ivars and @properties have the same default.

He said both the documentation (and warnings some people are getting) are wrong and will be fixed. (The conversion tool is correct.) Until that is done, I would avoid the implicit default altogether. Always explicitly specify "strong", "weak", or "assign".

Edit: The clang documentation now officially documents this change.

like image 86
nschum Avatar answered Nov 15 '22 14:11

nschum