Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARC properties' new attributes

I've read the transitioning to ARC notes and I still have a bit of confusion about properties' attributes we shoul/can use... We can use weak in place of assign (with the advantage that the property is set to nil if the object it points to is released), strong in place of retain and what in place of copy? We still use copy alone or do we need to couple strong with copy, such as property (strong,copy).. Maybe I need to practice and read again the doc because ARC is not very clear to me...

like image 679
Gianni Costanzi Avatar asked Oct 21 '11 20:10

Gianni Costanzi


2 Answers

The Clang ARC documentation has this to say:

copy implies __strong ownership, as well as the usual behavior of copy semantics on the setter.

Regarding custom setter methods, it has this to say:

A property's specified ownership is preserved in its metadata, but otherwise the meaning is purely conventional unless the property is synthesized.

So if you implement custom setters, you're responsible for implementing strong or weak semantics in those setters.

like image 118
rob mayoff Avatar answered Oct 17 '22 20:10

rob mayoff


Copy is implicitly strong, because it creates a copy and transfers ownership.

See this documentation:

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW18

like image 39
logancautrell Avatar answered Oct 17 '22 18:10

logancautrell