Objective-C multi-parameter method definition and call

Source: Internet
Author: User

Example of method definition:

-(Void) insertobject :( ID) anobject atindex :( nsinteger) Index

Explanations:

1. Method Modifier

-This method is an entity method. It must be a class instance and can be called only through an instance.

+ Indicates that this method is a static method of the class and can be called directly without generating a class instance.

 

2. Parameter type

ID and nsinteger are the anobject and index parameters respectively.

 

3. Method Signature

In this example, insertobject and atindex constitute the signature keyword of this method.

Here is an example:

-(Void) setto: (INT) n over: (INT) d

{
Numerator = N;
Denominator = D;
}

[Afraction setto: 100 over: 200]; // call

Note: The method parameter name of objective-C is somewhat odd. The first parameter does not have a parameter name. If it is hard to say yes, it is the method name,

In general, when we see the colon, the parameter name is prior to the colon.

 

For example, a method without a parameter name is defined and called:

 

-(INT) set: (INT) N: (INT) D; [afraction set: 1: 3]; // call

 

 

 

 

 

 

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.