just beginning to contact OC and then read the code written by others, often confused in the declaration of the attributes of the writing, summed up there are three ways, do not know which kind of comparative normalization, now I put three ways to paste out, and then one by one to discuss each way to declare the difference between attributes.
Method one: declared directly in the curly braces in @interface.
@interface mytest:nsobject{
NSString *mystr;
}
Way two: Declare in @interface, and then declare in @property.
@interface mytest:nsobject{
NSString *_mystr;
}
@property (Strong, nonatomic) NSString *mystr;
Then join in the. m file
@synthesize mystr = _mystr;
Way three: directly with @property declaration
@interface mytest:nsobject{
}
@property (Strong, nonatomic) NSString *mystr;
The @synthesize mystr = _mystr is then added to the. m file;
========================== I'm a split line ============================
First of all, the difference between the way a way three, the use of a declaration of the member variable is only within its own class use, and cannot be used outside the class,
(That is, by the class name.) Point of the way is not shown), the way three is the opposite, it can be accessed outside the class, within the class can be drawn by the line + variable name
or self. Variable name to access.
The way two is written is an obsolete way of declaring variables, and Xcode needs to be handwritten prior to the early @systhesize without automatic compositing of the properties.
Getter and setter method, underline style indicates that this is the internal variable of the class, if you need to use the variable directly, you need to use the way get or set.
After Xcode now has an auto-compositing property, the compiler will automatically help us generate an instance variable that starts with an underscore, so we don't have to declare the property at the same time.
with variables. We can declare a member property directly in the @property way, so it doesn't matter if you don't use @systhesize in. m files, and Xcode automatically generates getter and setter for you.
Individuals prefer to use mode three, which is recommended by the Apple Development template, and can also be seen in. m files without @systhesize.
Declaration of member variables @interface and @property