Re: Variable argument lists
Re: Variable argument lists
- Subject: Re: Variable argument lists
- From: Robert Martin <email@hidden>
- Date: Sat, 22 May 2004 11:18:20 -0400
Just use the standard C va_list/va_arg references and the normal
va_start...va_end block - and use id as the type. They should be
documented in any C book.
eg: this should move the args into an NSMutableArray...so your init
method can use count
//---------------------------------------------------------------------
+(Foo*) newFoo:(id) inFirst, ...
//---------------------------------------------------------------------
{
Foo * aFooObject = nil;
va_list argList;
NSMutableArray* argArray = [NSMutableArray array];
id anArg;
[argArray addObject: inFirst];
va_start( argList, anArg );
while( anArg = va_arg( argList, id ) ){
[argArray addObject: anArg];
}
va_end(argList);
aFooObject = [[[Foo alloc] initWithArgArray: argArray] autorelease];
return aFooObject;
}
On May 22, 2004, at 3:22 AM, Ken Tozier wrote:
I'm writing a class and would like to include an initialization method
like this one from NSDictionary:
+ (id) dictionaryWithObjectsAndKeys:(id) inFirst, ...
But I'm not really sure how to go about it. Could someone show me what
to do once I'm inside the initialization method?
+ (id) newFoo:(id) inFirst, ...
{
return [[[Foo alloc]
// is this the way to pass the arguments to the init method?
initFoo: inFirst]
autorelease];
}
- (id) initFoo:(id) inFirst, ...
{
self = [super init];
if (self)
{
// assuming I want to loop through the arguments
// what should go here?
}
}
Thanks,
Ken
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.