Properties
suggest changeVersions
The attributes below are those of Objective-C 2.0 properties and later.
Syntax
- @property (optional_attributes, …) type identifier;
- @synthesize identifier = optional_backing_ivar;
- @dynamic identifier;
Parameters
| Attribute | Description |
|---|---|
atomic |
Implicit. Enables synchronization in synthesized accessor methods. |
nonatomic |
Disables synchronization in the synthesized accessor methods. |
readwrite |
Implicit. Synthesizes a getter, a setter, and a backing ivar. |
readonly |
Synthesizes only the getter and backing ivar. The ivar can still be assigned directly. |
getter=name |
Name of the getter. The default is propertyName. |
setter=name |
Name of the setter. The default is setPropertyName:. The colon must be part of the name. |
strong |
Implicit for objects under ARC. The backing ivar is __strong, which keeps the referenced object alive. |
retain |
Synonym for strong. |
copy |
Like strong, but the synthesized setter stores -copy of the new value. |
unsafe_unretained |
Implicit, except for objects under ARC. The backing ivar is __unsafe_unretained, which (for objects) dangles after the referenced object is deallocated. |
assign |
Synonym for unsafe_unretained. Suitable for non-object types. |
weak |
The backing ivar is __weak, so the value becomes nil once the referenced object is deallocated. |
class |
Accessors are class methods instead of instance methods. No backing storage is synthesized. |
nullable |
The property accepts nil. Mainly used for Swift bridging. |
nonnull |
The property does not accept nil. Mainly used for Swift bridging. |
null_resettable |
The setter accepts nil, but the getter never returns nil. A custom getter or setter must ensure that. Mainly used for Swift bridging. |
null_unspecified |
Implicit. The property does not specify how nil is handled. Mainly used for Swift bridging. |
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents