Variable length parameters in Objective-C

前端 未结 3 1680
我在风中等你
我在风中等你 2021-01-07 03:55

How can i make a class method with variable length parameters, in Objective-C?

For example, a method like -arrayWithObjects:

NSArray *array = [NSArra         


        
3条回答
  •  礼貌的吻别
    2021-01-07 04:42

    What you need is a variadic function. These functions take a flexible number of arguments, like NSLog, [NSArray arrayWithObjects:...], etc.

    See this tutorial:

    http://www.numbergrinder.com/node/35

    Copied from my answer here: Obj-C, trying to write an alternative to NSLog, but I want my function to concatenate like NSLog?

提交回复
热议问题