gabor
gabor

Reputation: 4349

Is retain attribute for UIView properties with ARC required?

Before ARC, you would declare properties in your .h file as:

@property (nonatomic,retain) UIView *someUIView;

With ARC, do I still need to use retain or can I just write this?

@property (nonatomic) UIView *someUIView;

Upvotes: 0

Views: 609

Answers (2)

zpasternack
zpasternack

Reputation: 17898

In LLVM 3.1 and later, you can do either, because they're the same. Under ARC, strong (which is the same as retain) is the default, if not specified, for retainable object pointers.

Quoting from the LLVM ARC doc:

A property of retainable object pointer type which is synthesized without a source of ownership has the ownership of its associated instance variable, if it already exists; otherwise, [beginning Apple 3.1, LLVM 3.1] its ownership is implicitly strong. Prior to this revision, it was ill-formed to synthesize such a property.

I usually find myself typing "strong" anyway, I think because since assign was previously the default, it scares me for just a split second every time I see a retainable object property with no ownership specified.

Upvotes: 2

Michael Frederick
Michael Frederick

Reputation: 16714

The strong keyword has been advertised on place of retain, but they are really the same thing. So you can use strong or retain.

Your view WILL need to be retained by at least one object. If your view is already being retained by another object, you could make it an assign (aka weak) property. Otherwise you could keep the retain or strong keyword.

Upvotes: 1

Related Questions