Declaration and implementation of variable parameter methods in IOS

Source: Internet
Author: User

Ns_requires_nil_termination, for compile-time non-NIL end checks-(void) Mutableargumentsfunction: (NSString *) arg1, ... ns_requires_nil_termination{    //defines a pointer to an optional parameter list    va_list args;        Gets the address of the first optional parameter, at which point the argument list pointer points to the first optional parameter in the function argument list    va_start (args, arg1);    if (arg1)    {        //iterates through the parameters in the parameter list and causes the argument list pointer to point to the next parameter in the parameter list        nsstring *nextarg;        while ((Nextarg = Va_arg (args, NSString *))        {            NSLog (@ "ARG:%@", Nextarg);}    }    Ends the Get (empty argument list) of the mutable parameter    va_end (args);}


Special attention:

1. variable parameters can only be the last one in all parameters

2.ns_requires_nil_termination, for compile-time non-NIL end inspection

Application Scenarios:

1. Please refer to this method when rewriting Uialertview

2. Rewrite NSLog

Declaration and implementation of variable parameter methods in IOS

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.