1

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?

jscs
  • 63,694
  • 13
  • 151
  • 195
user1686342
  • 1,265
  • 1
  • 18
  • 24

2 Answers2

5

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

Hackmodford
  • 3,901
  • 4
  • 35
  • 78
  • Is using the first notation advisable/convention, or is the latter preferred for readability purposes? – user1686342 Nov 25 '15 at 14:27
  • Personally, I use the second one. I guess it's all up to what will be easier for you or how verbose you want to be. Do you think down the road, you'll come across the second example and remember that it is strong? Will you have to look this up again? – Hackmodford Nov 25 '15 at 14:29
  • Probably would which is fair enough. I'll stick to the second one. Thanks – user1686342 Nov 25 '15 at 14:30
0

From the documentation:

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

So both forms are the same.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • This is true when ARC is enabled, but under MRR, object-typed variables are not strong references. – jscs Nov 25 '15 at 22:34