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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to