Objective-C 语法是什么,椭圆式点表示法? “……”

2024-05-30

我在 Joe Hewitt 的 Three20 源代码中注意到了这一点,而且我以前从未在 Objective-C 中见过这种特殊的语法。甚至不知道如何在适当的谷歌搜索中引用它。

来自 UITableViewDataSource:

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

“……”是让我失望的地方。我假设它是一种枚举形式,可以提供可变数量的参数。如果是,该操作员的正式名称是什么?在哪里可以参考它的文档?

非常感谢你。


这是一个可变参数方法,这意味着它需要可变数量的参数。这一页 http://developer.apple.com/qa/qa2005/qa1405.html有一个很好的演示如何使用它:

#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);
  }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Objective-C 语法是什么,椭圆式点表示法? “……” 的相关文章

随机推荐