Objective C Quick Start 4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.