PropertyProbablyObjcUnique element inProgramming Mechanism, used to quickly generate class data membersGetAndSetMethod. This articleAbout mePropertySome usage experience.
1) Retain, copy, and assign:
Retain is used to generate the reference count + 1 of the data member (which must be an objc object) in the set method. It is usually used for objc objects other than the nsstring type. For example
-(Void) setmember :( member *) member <br/>{< br/> [member _ release]; <br/> member _ = [member retain]; <br/>}
A common exception is that the Set Method of delegate is usually set to assign, which is used to avoid the reference count caused by circular references not returning to 0, memory leakage-consider the situation where the delegate of a view is the controller of the view.
The Set Method of the nsstring class object is set to copy, and the string object needs to be copied in depth.
The Set Method of the variable should be set to assign.
2) elegantly release Member objects.
Taking controller as an example, the member object needs to be released in the viewdidunload method and dealloc method. The direct method is
[Member _ release];
The problem with this is that a wild pointer is generatedProgramUnexpected bugs may occur. If the program design is odd,
If you are lucky enough.
The elegant method is
Self. Member = nil;
Expand
[Member _ release]; <br/> member _ = nil;
3) nonatomic and atomic
Atomic is the meaning of atoms. In a multi-threaded program, the data members of atomic are locked during reading and writing, ensuring data security with a very small extra cost. Nonatomic assumes that the data member is not read and written by multiple threads at the same time.
My opinion-it is unrealistic to accurately determine whether a data member can be read and written by multiple threads at the same time in actual programming. Therefore, nonatomic is not required, and the additional overhead caused by this is negligible.
Misuse of nonatomic may cause unexpected bugs-if you are lucky enough.
4) private and public
We should try to set property to private-this will make the Class header file look much more concise. Generally, the property of almost all data members in a controller can be set to private -- otherwise, the program design may be faulty.