Variable number of method parameters in Objective C - Need an example

后端 未结 2 1280
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 05:58

From Objective C Programming Guide (Under the "Object Messaging" section),

Methods that take a variable number of parameters are also possible,

2条回答
  •  天涯浪人
    2021-01-06 06:43

    The syntax for declaring a method with a variable number of arguments is like this:

    - (void) printMyClass: (int) x, ...;
    

    One argument is always the required minimum, the others can be accessed via the va_arg function group. For the exact details, see this tutorial.

提交回复
热议问题