• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
***Junkmail*** How do I programaticly create a va_list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

***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


  • Follow-Ups:
    • Re: ***Junkmail*** How do I programaticly create a va_list
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: Re: NSTextField input validation
  • Next by Date: Re: Killall Finder Brings Hidden Apps To Front?
  • Previous by thread: Re: IKImageBrowserView drag and drop/reordering when using core data [SOLVED]
  • Next by thread: Re: ***Junkmail*** How do I programaticly create a va_list
  • Index(es):
    • Date
    • Thread