object-c 不定参数的实现(摘自Typhoon)

    
- (id)initWithConfigFileNames:(NSString*)configFileName, ...
{
    self = [super init];
    if (self)
    {
        va_list xml_list;
        _resourceNames = [NSMutableArray arrayWithObject:configFileName];

        va_start(xml_list, configFileName);
        NSString* resourceName;
        while ((resourceName = va_arg( xml_list, NSString *)))
        {
            [_resourceNames addObject:resourceName];
        }
        va_end(xml_list);
        [self parseComponentDefinitions];
    }
    return self;
}


  ————————用法:

TyphoonComponentFactory* factory;

   // factory = [[TyphoonBlockComponentFactory alloc] initWithAssemblies:@[       //非注入方式
  //      [PFCoreComponents assembly],
   //     [PFViewControllers assembly],
   //     [PFThemeProvider assembly]
   // ]];
   
    
    //依赖注入方式
   factory =
        ([[TyphoonXmlComponentFactory alloc] initWithConfigFileNames:@"CoreComponents.xml", @"ViewControllers.xml", @"Themes.xml", nil]);


相关参考:这里列举了一些关于object-c可变参数实现的链接,还有va_arg,va_start,va_end的使用的参考,有需要可以看一下。

你可能感兴趣的:(ios,可变参数,Object-C,typhoon)