Is declaring strong actually needed for Objective-C properties?

88 Views Asked by At

My understanding so far is that (retain) increases the reference count of a property and is essentially the exact same as (strong). Since all properties are set to retain by default (unless specified otherwise), is adding (strong) needed at all:

@property(nonatomic, strong) NSString *name;

Is the same as:

@property(nonatomic) NSString *name;

Both the above are the same, right?

2

There are 2 best solutions below

3
Hackmodford On BEST ANSWER

Since ARC was introduced, "strong", "atomic", and "readwrite" are set by default.

These properties are equivalent:

@property NSArray *name;
@property (strong, atomic, readwrite) NSArray *name;

Source: http://useyourloaf.com/blog/default-property-attributes-with-arc.html

1
vadian On

From the documentation:

By default, both Objective-C properties and variables maintain strong references to their objects.

So both forms are the same.