Parameters for @property:
We already know that in order to provide convenience to the developer, OC provides the @porperty keyword, which automatically generates the property's set and get methods.
But we also know that in OC we still face the problem of object memory management, and we follow the principle of "who created, who frees" to manage memory.
So we have to rewrite the Set method: Release the original member variable (object) and then retain the new member variable.
You also have to override the ReAlloc method: Call release in ReAlloc to release the object.
Oh. The purpose of introducing @property is to let it automatically generate set and get methods, and now we have to rewrite the set method, so we have to have a new solution.
In fact, the introduction of OC @property keyword is allowed to add parameters. There are a total of 3 types of parameters. When we do not write parameters, it defaults to:
@property (atomic,readwrite,assign) book *book;
Atomic means: multi-thread security;
ReadWrite: Both the value can be read and the value can be assigned (generate set and get method);
Assign: Do not perform memory management and assign values directly to a property.
There are 3 types of parameters for @property, and the following table is all parameter explanations:
In the absence of multi-threading problems, we choose the nonatomic parameter, it runs faster.
Because we have to do memory management, we have to write the retain parameter. It will first release the original object and then retain the new object. This way, you can replace manual override of the set method of this manual labor!
@property (nonatomic,retain) book *book;
Assign,retain,copy features of three parameters:
OC Syntax 7--memory management @property parameters