Local variables, member variables, and global variables
1. Inside a method, you can define a local variable with the same name as the member variable.
So within the scope of this local variable, he overrides the member variable.
2, if the definition and member variables with the same name as local variables, but also (ˇ?ˇ) want to manipulate local variables;
3, global variables, the entire file sharing, all methods shared;
A method that modifies this global variable in other ways uses this global variable to modify
4. There is a principle in the scope of variables: the nearest principle
Lookup order local variable-"member variable-" global variable
Self and Method
1. Self in the object method, it is the object that calls this method
2, self in the class method represents the class, he can call other class methods
Summarize:
Who calls this method then self is who
intAgenew = -;@implementationCzperson-(void) Changeage: (int) age{//_age =;// ////int _age = ten;// // //agenew = +;// //_age = age;// //self->_age = age;[Self setage: -];}- (void) Setage: (int) age{NSLog (@"Setage"); _age=Age ;}- (int) age{NSLog (@"agenew =%d", agenew); return_age;}+ (int) Sumofnum: (int) Num Andother: (int) other{returnNum +Other ;}+ (int) Averageofnum: (int) Num Andother: (int) other{return[Self sumofnum:num andother:other]/2;}@end
OC Base notes--self and Super (Guangzhou Black Horse first phase)