IOS learning notes (5) method with variable number of parameters, ios learning notes

Source: Internet
Author: User

IOS learning notes (5) method with variable number of parameters, ios learning notes

If you add a comma and three (,...) after the last parameter when defining the method, it indicates that the parameter can accept multiple parameter values.

To obtain variable parameters in a program, you need to use the following keywords:

·Va_list: This is a type used to define pointer variables pointing to the variable parameter list

·Va_start: This is a function that specifies to start processing the list of variable parameters and point the pointer variable to the first parameter in the Variable Parameter List.

·Va_end: stop processing variable parameters and release pointer variables.

·Va_arg: This function returns the value of the parameter currently pointed to by the pointer, and moves the pointer to the next parameter.

Example

Varargs. h

# Import <Foundation/Foundation. h> @ interface Varargs: NSObject // method for defining variable number of parameters-(void) test :( NSString *) name,...; @ end

Varargs. m

# Import "Varargs. h "@ implementation Varargs-(void) test :( NSString *) name ,... {// use va_list to define an argList pointer variable pointing to the variable parameter list va_list argList; // if the first name parameter exists, you need to process the parameter if (name) {// because the name parameter is not in the variable parameter list, you need to process the name parameter NSLog (@ "% @", name) first ); // set argList to the first parameter in the first variable parameter list and start to extract the parameter va_start (argList, name) in the Variable Parameter List ); // va_arg is used to extract the parameter currently pointed to by the argList pointer and move the pointer to the next parameter. // arg is used to save the currently obtained parameter. If this parameter is not nil, enter the cyclic body NSString * arg = va_arg (argList, id); while (arg) {// print each parameter. NSLog (@ "% @", arg); // extract the next parameter again and move the pointer to the next parameter arg = va_arg (argList, id );} // release the argList pointer and end the extraction of va_end (argList) ;}}@ end

Main Function

Int main (int argc, const char * argv []) {@ autoreleasepool {Varargs * va = [[Varargs alloc] init]; [va test: @ "Crazy iOS handout ", @ "crazy Android handout", @ "Crazy Ajax handout", nil];} return 0 ;}

Note: variable parameters can only be placed at the end of the parameter list. The greatest grace in a method gives you a variable-length parameter.

Refer to crazy iOS handout (I)


Where are ios study notes? Is it suitable for self-developed ios?

If you do not need to enter the training institution, you can learn it. If you do not need to pay the money, you must learn it. However, it depends on whether you have the self-control ability.
IOS applications are 1.4 times more than Android, while system developers are 0.38 times more than Android. This shows that the talent gap in the iOS industry is quite large. Because of this, the market is extremely pressing for Objective-C and C ++ developers, making the two occupations quite positive in employment trends, finally, it pushed the iOS industry to stride into the sunrise industry. In the current market environment that is in short supply, the increase in iOS talent salary is much higher than that of Android.

The next 10 years will be the mobile Internet era. This conclusion has become a consensus in the industry.
1: deploying iOS applications is a required strategic choice for enterprises.
2: the involvement of large enterprises will aggravate the shortage of iOS Talents
3: Code workers are rejected in the iOS field. The so-called experts are not only proficient in technology, but also understand users, the market, and design. The iOS field is dominated by compound and innovative talents.
 
What are ios mobile app development study notes?

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.