• 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
Re: Programmatically constructing list of variable arguments?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Programmatically constructing list of variable arguments? (From: "Jonathan del Strother" <email@hidden>)
 >Re: Programmatically constructing list of variable arguments? (From: "Kyle Sluder" <email@hidden>)
 >Re: Programmatically constructing list of variable arguments? (From: "Kyle Sluder" <email@hidden>)
 >Re: Programmatically constructing list of variable arguments? (From: "Jonathan del Strother" <email@hidden>)
 >Re: Programmatically constructing list of variable arguments? (From: email@hidden)

  • Prev by Date: Re: Looking for info on creating Plugins/Modules
  • Next by Date: Re: Looking for info on creating Plugins/Modules
  • Previous by thread: Re: Programmatically constructing list of variable arguments?
  • Next by thread: Re: Programmatically constructing list of variable arguments?
  • Index(es):
    • Date
    • Thread