我有一个具有可选参数的指定初始化程序(类似于下面的代码),我想通过调用它来创建一个autorelease方法。有没有办法做到这一点?如何将可选参数发送到另一个函数/方法?
@interface MyObject : NSObject
- (id)initWithArgs:(id)firstArg, ...;
+ (id)objectWithArgs:(id)firstArg, ...;
@end
@implementation MyObject
- (id)initWithArgs:(id)firstArg, ...
{
if (!firstArg || ![super init]) {
return nil
}
va_list argList;
va_start(argList, firstArg);
id currentObject = firstArg;
do {
NSLog(@"%@", currentObject);
} while ((currentObject = va_arg(argList, id)) != nil);
va_end(argList);
return self;
}
+ (id)objectWithArgs:(id)firstArg, ...
{
// return [[[MyObject alloc] initWithArgs:firstArg, ...] autorelease];
}
@end
下一次搜索网站首先,这里有大量的重复项目。 – 2009-07-26 18:28:29