Re: Variable arguments at runtime modification
Re: Variable arguments at runtime modification
- Subject: Re: Variable arguments at runtime modification
- From: Bertrand Mansion <email@hidden>
- Date: Sun, 12 Oct 2003 17:56:31 +0200
Chris Ridd wrote:
>
However NSString does not seem to have a variant of the stringWithFormat
>
class method that takes a va_list argument, so you're sadly out of luck. It
>
sounds like a relatively useful and straightforward extension, so you could
>
raise an enhancement request on Radar.
Hi Chris,
Thanks for your help. Actually, I've found this method that can probably
handle it:
- (id)initWithFormat:(NSString *)format arguments:(va_list)argList;
But that doesn't solve my problem yet. How to create or modify a va_list
from inside a method and then pass it to another method ?
Here is my modified code, maybe it's clearer:
- (void)queryWithFormat:(id)format, ...
{
va_list values;
id value;
NSString *query;
va_start(values, format);
while ((value = va_arg(values, id)) != nil) {
if ([value isKindOfClass:[NSData class]]) {
// Encode binary NSData to NSString
} else {
// Keep value as it is now
}
}
va_end(values);
query = [NSString initWithFormat:format arguments:XXX];
return query;
}
The XXX is my problem. How can I create a new va_list for initWithFormat
with my NSData encoded to NSString ? My goal is to let the framework user
pass NSData as well as NSString to this queryWithFormat method and have the
method automatically encode NSData to NSString when needed, then create the
new, clean, encoded string.
I thought about using an NSArray with the values but there is no NSString
method to create a string using a format with objects from a NSArray. That
would be handy (more flexible than va_list IMO).
Or maybe I could change what va_arg returns at runtime but that seems risky
as my encoded NSString are larger than the given NSData. And I don't even
know if it's possible.
Thanks,
Bertrand Mansion
Mamasam
http://cocoa.mamasam.com
PS: please include my email address in the reply cc as I only receive
digests of the list. Thank you :)
_______________________________________________
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.