abs
abs

Reputation: 176

Xcode 4.2.1 ARC issue

a project which is iOS5 only and ARC enabled compiles on Xcode 4.3.1 beta. When compiling on 4.2.1. LLVM is throwing warnings like these:

"ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute"

So the property definitions looks like this:

@property (nonatomic) NSObject* object

ARC is enabled in Build Settings. Adding a strong attribute fixes this warning but this should be default right?

Is there a difference between the Xcode versions in handling those property defaults?

Thanks Andi

Upvotes: 3

Views: 663

Answers (1)

NJones
NJones

Reputation: 27147

This is not beta specific Xcode 4.2.1 has the same behavior (betas are under NDA and should only legally be discussed in apple's developer forums):

Strong is the default setting for ivars. For ivars if you want __unsafe_unretained or __weak you must specify.

It has always been best practice to specify attributes in property declarations. One example that pops most quickly to mind is the UILabel property text, defined as:

@property(nonatomic,copy) NSString *text; // default is nil

In this example the copy attribute tells me I can pass an NSMutableString reference to the label and it will make a copy and I can go on mutating the string the label will remain the same. The behavior is clearly defined.

And I suspect it's the clearly defined behavior which was the most prominent reason that the ARC compiler forces you to specify storage attributes. Remember with the new runtimes eliminating the need to declare ivars for properties and @synthesize for accessor methods, it's conceivable that the property declaration is the only point you will notice if you accidentally retained a delegate.

Also consider the possibility that a few classes in a project may have been excluded from ARC in these cases there internal implementation would be completely opaque to ARC.

Upvotes: 4

Related Questions