Re: Variadic arguments to methods in Objective-C - How ?
Re: Variadic arguments to methods in Objective-C - How ?
- Subject: Re: Variadic arguments to methods in Objective-C - How ?
- From: Vincent Coetzee <email@hidden>
- Date: Sat, 8 Jan 2005 22:50:32 +0200
Specifically I was extending NSArray as follows
@implementation NSArray (NSArrayExtensions)
+ (NSArray*) arrayWithInts: (int) count,...
{
va_list ap;
NSMutableArray* array;
int index;
array = [[[NSMutableArray alloc] init] autorelease];
va_start(ap,count);
for (index=0;index<count;index++)
{
[array addObject: [NSNumber numberWithInt: *((int*)ap)]];
va_arg(ap, int);
}
va_end(ap);
return(array);
}
@end
works like a charm, altho if there is a better way to do this I am all
ears !
Thanks
Vincent
On Jan 08, 2005, at 22:22, Andreas Mayer wrote:
Am 8. Jan 2005 um 20:38 Uhr schrieb Vincent Coetzee:
So can I use the normal C mechanism and if not how is it done ?
Usually you just use an NSArray or NSDictionary and populate it with
the arguments.
- (void)doSomethingWithLotsOfArgumentsFromArray:(NSArray *)theArguments
{
id argumentOne = [theArguments objectAtIndex:0];
...
}
[yourObject doSomethingWithLotsOfArgumentsFromArray:[NSArray
arrayWithObjects:@"one", @"two", nil]];
Andreas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40wallflower.co.za
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden