When I started learning iOS, I didn't understand some of the OBJC grammars, like @property and @synthesize, before remembering and then using them, but writing more code, having some understanding of OBJC and iOS, plus the recent MRC, So in a variety of memory detection and variable use of the process, discussed, and finally the role of them have a certain understanding.
General @property and @synthesize are used in conjunction with @property declared variables, the system defaults to them to do setter and getter processing.
Property can declare various properties of an attribute.
1. declaring a property's access method:
- Getter=gettername
- Setter=settername
Declares the setting of the Access property and gets the method name.
2. declaring attribute Write permissions:
- ReadWrite
Declares that this property is read-write, that is, you can access the Set method (setter), or you can access the Get method (getter), which is mutually exclusive with ReadOnly.
- ReadOnly
Declares that this property is read-only and can only access the Fetch method (getter) corresponding to this property, which is mutually exclusive with ReadWrite.
3. implementation of declarative write methods
4. atomicity of the access method
For atomicity, you can check the atomic operation of the operating system.
The name of a getter and setter that is not the same as the variable name can be defined in the @synthesize to protect the variable from inappropriate access.
function: Let the compiler automatically write a method declaration with the same name as the data member, omitting the declaration of the read-write method.