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;
First of all, the difference between the way a way three, the use of a declared member variable is only within its own class use, and cannot be used outside the class, (that is, through the class name.) Point is not shown), the way three is the opposite, it can be accessed outside the class, inside the class can be accessed by the underscore + variable name or self. Variable name.
The way two is written is an obsolete way of declaring variables, and Xcode requires a handwritten getter and setter method in the early @systhesize without the automatic compositing of the property, underlining the style that this is the internal variable of the class. If you need to use variables directly, you need to use the Get or set method.
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 and the variable at the same time. 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.
IOS OC Declares the difference between @interface brackets and the use of @property