Re: Programmatically constructing list of variable arguments?
Re: Programmatically constructing list of variable arguments?
- Subject: Re: Programmatically constructing list of variable arguments?
- From: "Michael Ash" <email@hidden>
- Date: Sat, 13 Dec 2008 00:19:12 -0500
On Fri, Dec 12, 2008 at 12:02 PM, Jonathan del Strother
<email@hidden> wrote:
> On Fri, Dec 12, 2008 at 4:42 PM, Michael Ash <email@hidden> wrote:
>> On Fri, Dec 12, 2008 at 9:41 AM, Jonathan del Strother
>> <email@hidden> wrote:
>>> Maybe an example would be helpful. Let's say I want to call
>>> -[Bartender mixCocktailIngredients:(NSString*)ingredient ...], and I
>>> want to call that with different arguments depending on the user's
>>> preferences.
>>> One way of doing so would be to use an if-statement, and just type out
>>> all the possibilities:
>>
>> Why don't you just rewrite -mixCocktailIngredients: to take an NSArray
>> instead of variable arguments? Seems like that's ultimately what you
>> need anyway, so just change it to be more sane. If you really love
>> variable arguments then you can write a vararg version that calls
>> through to the NSArray version after marshaling the arguments.
>
> Sure, if -mixCocktailIngredients: was my own method, but it's not.
> I'm calling something in an existing API.
Are you sure there's no non-vararg way to accomplish it? I would
consider any API that requires the use of varargs to use multiple
objects to be broken. Of course sometimes APIs really are broken and
you have to work around that, but I'd definitely first try searching
for a way around having to do what you request, or convincing whoever
is responsible for this API to un-break it and provide a non-vararg
method.
Mike
_______________________________________________
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