在Objective-C可变长度参数 [英] Variable length parameters in Objective-C
问题描述
我怎样才能使一个类的方法长度可变的参数,在Objective-C?
例如,像-arrayWithObjects的方法:
的NSArray *阵列= [NSArray的arrayWithObjects:@1,@2,@3,零]
您需要的是一个可变参数函数。这些功能需要的参数灵活一些,如的NSLog
, [NSArray的arrayWithObjects:...]
等
请参阅本教程:
http://www.numbergrinder.com/node/35
在这里我的答案复制:<一href=\"http://stackoverflow.com/questions/4864901/obj-c-trying-to-write-an-alternative-to-nslog-but-i-want-my-function-to-concate/4864998#4864998\">Obj-C,试图写NSLog的另一种选择,但我想我的功能来连接NSLog的一样?
How can i make a class method with variable length parameters, in Objective-C?
For example, a method like -arrayWithObjects:
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
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 ?
这篇关于在Objective-C可变长度参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!