The syntax for declaring property is:@ Property (attribute [, attribute 2,...])Type name;
There are three types of attributes:
1. read/write attributes (writability) include: readwrite/readonly
2. setter semantics (setter semantics) includes: Assign/retain/copy
3. atomicity (Atomicity) includes: nonatomic
The following describes the meaning of each attribute.
Readwrite/readonly:
Determines whether to generate the set accessors. readwrite is the default attribute and generates the getter and setter methods. readonly only generates the getter method and does not generate the setter method.
The readonly keyword indicates that the setter will not be generated, so it cannot be used in combination with copy/retain/assign.
Assign/retain/copy:
These attributes are used to specify the semantics of the Set accessors. That is, these attributes determine how to assign new values to data members.
Assign:
Direct value assignment, index count unchanged, applicable to simple data types, such as nsingeter, cgfloat, Int, Char, etc.
Retain:
The pointer copy uses the original memory space.
The index count of the object is increased by 1.
This attribute can only be used for the objective-C object type, but not for the core foundation object. (The reason is obvious: retain will increase the reference count of the object, and neither the basic data type nor the core foundation object has reference count ).
Copy:
Copy the object, apply for a new memory space, and copy the original content to that space.
The index count of the new object is 1.
This attribute is only valid for object types that implement the nscopying protocol.
In many objective-C objects, it is best to use retain. For some special objects (such as string), copy is used.
Nonatomic:
Non-atomic access without synchronization. multi-thread concurrent access improves performance. If this attribute is not added, both access methods are atomic transaction access by default. The default value is atomic, which is an atomic operation.
(Atomic is a thread protection technology used by objc. Basically, it is used to prevent reading by another thread when the write is not completed, resulting in data errors. This mechanism consumes system resources. Therefore, nonatomic is a good choice for small devices such as the iPhone, if multi-thread communication programming is not used .)
The syntax for declaring property is:@ Property (attribute [, attribute 2,...])Type name;
There are three types of attributes:
1. read/write attributes (writability) include: readwrite/readonly
2. setter semantics (setter semantics) includes: Assign/retain/copy
3. atomicity (Atomicity) includes: nonatomic
The following describes the meaning of each attribute.
Readwrite/readonly:
Determines whether to generate the set accessors. readwrite is the default attribute and generates the getter and setter methods. readonly only generates the getter method and does not generate the setter method.
The readonly keyword indicates that the setter will not be generated, so it cannot be used in combination with copy/retain/assign.
Assign/retain/copy:
These attributes are used to specify the semantics of the Set accessors. That is, these attributes determine how to assign new values to data members.
Assign:
Direct value assignment, index count unchanged, applicable to simple data types, such as nsingeter, cgfloat, Int, Char, etc.
Retain:
The pointer copy uses the original memory space.
The index count of the object is increased by 1.
This attribute can only be used for the objective-C object type, but not for the core foundation object. (The reason is obvious: retain will increase the reference count of the object, and neither the basic data type nor the core foundation object has reference count ).
Copy:
Copy the object, apply for a new memory space, and copy the original content to that space.
The index count of the new object is 1.
This attribute is only valid for object types that implement the nscopying protocol.
In many objective-C objects, it is best to use retain. For some special objects (such as string), copy is used.
Nonatomic:
non-atomic access without synchronization, multi-thread concurrent access improves performance. If this attribute is not added, both access methods are atomic transaction access by default. The default value is atomic, which is an atomic operation.
(atomic is a thread protection technology used by objc. Basically, it is used to prevent reading by another thread when the write is not completed, resulting in data errors. This mechanism consumes system resources. Therefore, nonatomic is a good choice for small devices such as the iPhone, if multi-thread communication programming is not used .)