Class
1. Method of merging accessors
@ Property member variable
@ Synthesize member variable
Allows the compiler to automatically combine methods for setting and obtaining functions. You do not need to manually generate set member variables or get member variables.
@ Interface complex: nsobject
{
Int ireal, iimag;
}
@ Property int ireal, iimag; // method of merging accessors. Part 1: @ property identity attribute
-(Void) print;
@ End
@ Implementation Complex
@ Synthesize ireal, iimag; // The method for merging accessors. Step 2: Tell the compiler to automatically generate accessors.
-(Void) print
{
Nslog (@ "ireal = % I, iimag = % I", ireal, iimag );
}
@ End
2. Call methods and members
[Mycomplex print];
Or mycomplex. Print
[Mycomplex ireal];
Or mycomplex. ireal
3. Multiple Parameter Methods
One method sets both the real and virtual parts
-(Void) setreal: (INT) n setimag :( INT) d
You can also omit the parameter name.
-(Void) setcomplex :( INT) n :( INT) d
4. Point to the instance itself. Self is equivalent to C ++ this