id: 11734    nodeId: 11734    type: General    point: 128.0    linkPoint: 1.0    maker: cella    permission: linkable    made at: 2013.05.08 02:13    edited at: 2013.05.08 02:15
property in Objective-C
http://stackoverflow.com/questions/4510913/objective-c-assign-copy-retain
Have you read the documentation? The Property Declaration Attributes section of the Objective-C Programming Language guide describes them this way:

assign - "Specifies that the setter uses simple assignment. This is the default. You typically use this attribute for scalar types..." So you can imagine assigning a float (which isn't an object, so can't be retained, copied, etc.).

retain - "Specifies that retain should be invoked on the object upon assignment. ... The previous value is sent a release message." So you can imagine assigning an NSString instance (which is an object and which you probably want to retain).

copy - "Specifies that a copy of the object should be used for assignment. ... The previous value is sent a release message." Basically same as retain, but sending -copy rather than -retain.

The retain/copy concepts come from the reference-counted memory management system.

Essentially, when used with @synthesize directive (to synthesize the property accessors you would otherwise write - like -person or -setPerson:), it determines how memory is managed inside the setter.

share|improve this answer
answered Dec 22 '10 at 16:00

Joshua Nozzi
31k36072

Return to re: 베이징나비 or property in Objective-C