Property is a code generation mechanism that can generate different types of getter/setter functions, especially if you want to use vertex (.) to access a variable, you must use the property.
How to use it?
Usage example: @ property (attribute1, attribute2) float value;
These attributes include:
Readonly-Read-only, read-only, but not set value (the setxxxx function cannot be used ).
Readwrite-Readable and writable (default ).
Assign-Replace the old and new variables (default) when setting values ).
Retain-When the value is set, the new variable is retain, and the old variable is release.
Copy-Copy a new variable when setting the value, and release the old variable.
Nonatomic-The default value is atomic.
Strong-In the reference counting environment, strong is assumed to be the same as retain;
Weak was introduced from the 5.0 system. Its function is similar to assign, but it is automatically set to nil when the referenced object is 0.
The first two are just simple settings of variable readability.
Assign is just a simple replacement of variables, usually used in scalar types, such as nsinterger and cgrect,
Or (in the reference counting environment) for objects you do not own, such as delegates.
In the garbage collection environment, retain and assign are actually the same.
The content of the setter code generated by it is similar:
-(Void) setvalue :( float) newvalue {
Value = newvalue;
}
Another important thing to note is that when using property, you must add self (such as self. XXX) to the front. If you do not do this, easy causes memory leakage.
Object-c @ property usage