Re: Programmatically constructing list of variable arguments?
Re: Programmatically constructing list of variable arguments?
- Subject: Re: Programmatically constructing list of variable arguments?
- From: "Jonathan del Strother" <email@hidden>
- Date: Fri, 12 Dec 2008 17:03:42 +0000
On Fri, Dec 12, 2008 at 2:54 PM, <email@hidden> wrote:
>
> On 12 Dec 2008, at 15:41, Jonathan del Strother wrote:
>
>> Which works fine, but rapidly expands into a huge if-statement as you
>> try and handle more states. Ideally I'd like to do something along
>> the lines of:
>>
>> NSMutableArray* ingredients = [NSMutableArray arrayWithObjects:@"gin",
>> @"vodka", nil];
>> if (user.likesTequila)
>> [ingredients addObject:@"tequila"];
>>
>> [bartender mixCocktailIngredients: NSArrayToVariableList(ingredients)];
>
>
> How about something like this:
>
> const int kMaxNumberOfIngredients = 50;
>
> NSString* a[kMaxNumberOfIngredients];
> // Zero out a
>
> [ingredients getObjects:a]; // Assumes no more than 50 objects in
> ingredients, will crash otherwise
>
> [bartender mixCocktailIngredients: a[0], a[1], a[2] ..... a[48], a[49]];
>
> A little clunky, but it should be usable if the max possible options in
> known in advance and not excessive.
> Also assumes that mixCocktailIngredients method really does check for nil
> terminator instead of count of arguments
Ugly, but a lot easier than figuring out libffi. Thanks for the suggestion.
_______________________________________________
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