Objective-C Class interface (@ Interface) (class definition)

Source: Internet
Author: User

In objective-C, how do I define a class? We can use the following format for representation:

 
@ Interface Class Name: parent class name {variable definition;} method definition; @ end;

An example is provided below:

 
@ Interface person: nsobject {nsstring * Name; int age;}-(nsstring *) Name;-(INT) age;-(void) setname: (nsstring *) input; -(void) setage: (INT) input; @ end;

The class definition starts with @ interface. It indicates the interface declaration of the class, and specifies the parent class of the class after the colon, @ end; indicates that the class definition ends.

In objective-C's class definition, the class variable definition is separated from the method definition. The variable definition is written in curly brackets, and the method definition of the class is written out of curly brackets. The method definition is unique. The specific format is as follows:

-(Void) setname: (nsstring) input;

Method Type return type method name method accept parameter type parameter name

The general format is as follows:

+/-(Return type) Sub-1 :( type 1) parameter 1 sub-2 :( type 2) parameter 2...

The method with a minus sign (-) is an instance method. You must use an instance of the class to call this method.

There is a plus sign, which indicates a static method of the class and can be called without instantiation.


Method definition of a parameter:

-(Void) setname: (nsstring *) input;

Method definition of the two parameters:

-(Void) setname: (nsstring *) Input andsecondname :( nsstring *) input1;

Related Article

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.