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

Matt
_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to