On Wed, Aug 21, 2013 at 2:35 AM, Dave <d...@looktowindward.com> wrote:

> -(void) methodX:(NSString*) theName,…
> {
> va_list
> myArgumentList;
> NSInteger
> myArgumentCount;
>
> myArgumentCount = 0;
> va_start(myArgumentList,theMethodName);
>
> while(va_arg(myArgumentList,NSString*) != nil)
>  //********************
>         myArgumentCount++;
>

Whatever else you're trying to do, you cannot write a loop like that.
va_arg() will NOT return nil/NULL/0 when it reaches the end. In fact,
va_arg() has no possible way of knowing when it has reached the end. That's
why you pass in theName; it's 100% up to you to parse theName and figure
out how many arguments were passed in and call va_arg() properly.

Or, alternately, force all of your arguments to be of a common base type
(say, "id") and nil terminate the list. A la +[NSArray arrayWithObjects:],
etc.

But you can't have it both ways.

Once you have that your while() loop is easy:

while (more_arguments) {
  argument_type = get_next_arg_type();
  if (argument_type == myNSStringType) {
    objVal = va_arg(myArgList,NSString*);
  } else if (argument_type == myNSIntegerType) {
    intVal = va_arg(myArgList,NSInteger);
  } ... etc ..

  more_arguments = has_more_arguments();
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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

This email sent to arch...@mail-archive.com

Reply via email to