Prior to learning C + +, or Java, there was a visibility issue, and this article discussed the visibility of declared member variables on object methods (minus methods) and class methods (plus methods).
(a) Code one: member variables are visible to the minus method, not visible to the plus method.
Declare a member variable in PEOPLE.M: NSString *_peoplename, and then find that the variable can be accessed in the minus method and not accessible in the Plus method.
-(void) ObjectShow {
NSLog (@ "I am an object method");
[email protected] "member variables"; // You can access member variables here;
}
+ (void) ClassShow {
NSLog (@ "I am a class method");
// Cannot access _peopleName here;
}
(b) Code two: static member variables are visible to the minus method, and to the plus method.
Use static (familiar with Java-learning) keywords in people.m to declare a static variable: static NSString *_peoplename2; You can then discover that the static variable can be accessed both in the minus and plus methods.
-(void) ObjectShow {
NSLog (@ "I am an object method");
[email protected] "Jack"; // A static variable was accessed in the object method;
}
+ (void) ClassShow {
NSLog (@ "I am a class method");
[email protected] "Mike"; // A static variable was accessed in the class method;
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Objective-c Study Notes (20)--analysis of the visibility of member variables on object methods and class methods