Skip to content

Instantly share code, notes, and snippets.

@andrewsardone
Created November 15, 2011 16:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewsardone/1367501 to your computer and use it in GitHub Desktop.
Save andrewsardone/1367501 to your computer and use it in GitHub Desktop.
Objective-C @Property declaration cheat sheet – http://git.io/objcproperty

@property(<atomicity>, <writability>, <setter semantics>)

<atomicity>

nonatomic – Specifies that accessors are nonatomic. By default, accessors are atomic.

<writability>

readwrite – Indicates that the property should be treated as read/write. This attribute is the default.

readonly – Indicates that the property is read-only.

<setter semantics>

strong – Specifies that there is a strong (owning) relationship to the destination object. (ARC)

weak – Specifies that there is a weak (non-owning) relationship to the destination object. If the destination object is deallocated, the property value is automatically set to nil. (not supported in iOS 4; use assign instead)

copy – Specifies that a copy of the object should be used for assignment, releasing the previous value and copying the incoming value (only valid for objects that implement the NSCopying protocol).

assign – Specifies that the setter uses simple assignment. This attribute is the default. (use for scalar types, weak references in iOS 4, etc.)

retain – Specifies that retain should be invoked on the object upon assignment. The previous value is sent a release message.

via Apple's Developer Documentation

@KevinVitale
Copy link

4.1.1. Property declarations

A property of retainable object pointer type may have ownership. If the property's type is ownership-qualified, then the property has that ownership. If the property has one of the following modifiers, then the property has the corresponding ownership. A property is ill-formed if it has conflicting sources of ownership, or if it has redundant ownership modifiers, or if it has __autoreleasing ownership.

assign implies __unsafe_unretained ownership.
copy implies __strong ownership, as well as the usual behavior of copy semantics on the setter.
retain implies __strong ownership.
strong implies __strong ownership.
unsafe_unretained implies __unsafe_unretained ownership.
weak implies __weak ownership.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment