Variable length parameters in Objective-C

江枫思渺然 提交于 2019-12-01 00:54:18
Evan Mulawski

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?

Take a look at varargs, e.g.: Apple Technical Q&A QA1405. It shouldn't matter whether the method is a class method or not.

Methods that take variable arguments are known as variadic methods. The "..." is the variable argument.
For example, your function declaration would be: - (void)specialWithX:(NSInteger)x y:(NSInteger)y, ...;

For additional information take a look at Variable argument lists in Cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!