***Junkmail*** How do I programaticly create a va_list
***Junkmail*** How do I programaticly create a va_list
- Subject: ***Junkmail*** How do I programaticly create a va_list
- From: Horst Jäger <email@hidden>
- Date: Tue, 13 Jan 2009 17:32:23 +0100
Hi,
I have a problem concerning the va_list. I don't know how to
programaticly create one.
I need to do this because I want to use the initWithFormat method of
NSString. But I neither know how many args there will be nor are the
args Strings - they are selectors the associated methods of which
return Strings.
Suppose the initWithFormat method of NSString worked with an array
instead of a va_list (Syntax: - (id)initWithFormat:(NSString *)format
arguments: (NSArray *)args)
Then I could convert the array of selectors into an array of NSStrings
and my function would look like this:
(NSString *)formattedTextForClass: (Class)targetClass:
withFormat(NSString *)format withArguments: (NSArray *)selectors{
// do the conversion
NSMutableArray results = [[NSMutableArray alloc] init];
for(int iter = 0; iter < [selectors count]; ++iter){
SEL selector = [selectors objectAtIndex: iter];
NSString *result = [targetClass performSelector: selector];
[results addObject: result];
}
// use the converted list
// unfortunately it doesn't work like this
NSString *retval = [[NSString alloc] initWithFormat: format
withArguments: results];
[results release];
return retval;
}
But the initWithFormat method of NSString works with a va_list instead
of an array. So - if I knew how to do the converison in the va_list -
my function would look (at least a little) like this:
(NSString *)formattedTextForClass: (Class)targetClass:
withFormat(NSString *)format withArguments: (va_list)selectors{
// do the conversion
// unfortunately I don't know how to do that
va_list results = [self somehow_get_the_converted_va_list: selectors];
// use the converted list
NSString *retval = [[NSString alloc] initWithFormat: format
withArguments: results];
[results release];
return retval;
}
And I would call it like this:
NSString *myFormattedText = [MyFormatter formattedTextForClass:
[SomeClass class], @selector(firstSelector),
@selector(secondSelector), @selector(thirdSelector), nil];
Any help would be very much appreciated. Thanks in advance!
Horst
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden