Synthesis and access methods in OC
First, you must declare the differences between instance variables and attributes.
Instance variables:
/// Interface file
# Import
-(Int) a; // instance variable
-(Int) B;
-(Void) fun1;
...
@ End
/// Implementation file
# Import "XXX. h"
@ Implementation XXX
{
Int a; // instance variable
Int B;
}
-(Void) fun1
{
...
}
...
@ End
Attribute:
@ Interface XXX: NSObject
@ Property int a, B; // @ property command
-(Void);
...
@ End
Note:
1. If attributes are declared, you do not need to declare them again in implementation.
2. @ synthesize
@ Synthsize a and B are often displayed in the implementation file. In this way, two value Methods a and B are implemented, and two setting methods seta and setb are implemented;
But this line does not actually work, and the compiler will automatically generate setter and getter for you. However, the attribute name generated by the compiler will automatically be underlined in the first character. For example, _ a, _ B;
It is worthwhile for the compiler to generate an automatic access method.