什么是Objective-C语法,椭圆风格点符号? “...”

什么是Objective-C语法,椭圆风格点符号? “...”

问题描述:

我在Joe Hewitt的Three20的来源注意到了这一点,我从来没有在Objective-C中看到这种特殊的语法。甚至不确定如何在适当的Google搜索中引用它。

I noticed this in Joe Hewitt's source for Three20 and I've never seen this particular syntax in Objective-C before. Not even sure how to reference it in an appropriate Google search.

从TTTableViewDataSource:

From TTTableViewDataSource:

+ (TTSectionedDataSource*)dataSourceWithObjects:(id)object,... {

...是什么让我离开这里。我假设它是一种枚举形式,其中可以提供可变量的参数。如果是,这个操作符的官方名称是什么,在哪里可以参考它的文档?

The "..." is what's throwing me off here. I'm assuming it's a form of enumeration where a variable amount of arguments may be supplied. If it is, what's the official name for this operator and where can I reference the documentation for it?

谢谢你。

这是一个可变的方法,意味着它需要可变数量的参数。 此网页有如何使用它的良好示范:

It's a variadic method, meaning it takes a variable number of arguments. This page has a good demonstration of how to use it:

#import <Cocoa/Cocoa.h>

@interface NSMutableArray (variadicMethodExample)

- (void) appendObjects:(id) firstObject, ...;  // This method takes a nil-terminated list of objects.

@end

@implementation NSMutableArray (variadicMethodExample)

- (void) appendObjects:(id) firstObject, ...
{
id eachObject;
va_list argumentList;
if (firstObject)                      // The first argument isn't part of the varargs list,
  {                                   // so we'll handle it separately.
  [self addObject: firstObject];
  va_start(argumentList, firstObject);          // Start scanning for arguments after firstObject.
  while (eachObject = va_arg(argumentList, id)) // As many times as we can get an argument of type "id"
    [self addObject: eachObject];               // that isn't nil, add it to self's contents.
  va_end(argumentList);
  }
}