Description and implementation of Variable Parameter methods in iOS

Source: Internet
Author: User

Description and implementation of Variable Parameter methods in iOS

// NS_REQUIRES_NIL_TERMINATION, used for checking non-nil end at compilation-(void) mutableArgumentsFunction :( NSString *) arg1 ,... NS_REQUIRES_NIL_TERMINATION {// defines a pointer to the optional parameter list va_list args; // gets the address of the first optional parameter, in this case, the parameter list Pointer Points to the first optional parameter va_start (args, arg1) in the function parameter list; if (arg1) {// traverses the parameters in the parameter list, and point the parameter list pointer to the next parameter NSString * nextArg; while (nextArg = va_arg (args, NSString *) {NSLog (@ "ARG: % @", nextArg) ;}}// get the final variable parameter (clear the parameter list) va_end (args );}


Note:

1. variable parameters can only be the last of all parameters

2. NS_REQUIRES_NIL_TERMINATION, used for non-nil end check during compilation

Application scenarios:

1. You can refer to this method when rewriting UIAlertView.

2. Rewrite NSLog

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.