• 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
Variable Number of Parameters in Method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Variable Number of Parameters in Method


  • Subject: Variable Number of Parameters in Method
  • From: Dave <email@hidden>
  • Date: Wed, 21 Aug 2013 08:35:50 +0100

Hi,

I have a method that takes one fixed parameter and then a variable number of parameters, the method is defined as:

-(void) methodX:(NSString*) theName,…



The variable parameter list in this case can contain values of any type, e.g. an Object pointers, Integers, Floats etc, as in:

NSString*			myString;
NSInteger			myIntValue1;
NSUInteger*			myUIntValue1;
CGFloat*			myFloatValue;

[myObj methodX:@"Name1",myString,myIntValue1,myUIntValue1,myFloatValue];



I've written code to work with variable parameter lists in the past, but previously, I always knew the expected size of the values at compile time, and they followed a fixed pattern, e.g.

Obj*,Obj*,NSInteger,    etc.


But in this, the parameters can be in any order and any time, I do know the size of each parameter at *Run-Time*, e.g. I use "theName" parameter which is used to bring back a string of the types for a given name, for example, in the call:

[myObj methodX:@"Name1",myString,myIntValue1,myUIntValue1,myFloatValue];

methodX would use "Name1" as a key to a dictionary which brings back the following in this case:

NSString*,NSInteger,NSInteger,CGFloat,

I can use this to figure out the length of the parameter in the method call, for example:

NSString*	4
NSInteger	4
CGFloat		8

My problem is I can't figure out how to pass in this raw value to the "va_" functions/macros. See snippet below:


-(void) methodX:(NSString*) theName,…
{
va_list								myArgumentList;
NSInteger							myArgumentCount;

myArgumentCount = 0;
va_start(myArgumentList,theMethodName);

while(va_arg(myArgumentList,NSString*) != nil)		//********************
	myArgumentCount++;

va_end(myArgumentList);

…….
…….
…….
}

This is supposed to count the number of parameters, but will fail because it is assuming a size of 4 (NSString) in:

 va_arg(myArgumentList,NSString*)

 What I would like to be able to do is to pass in the raw value, something like, va_argWithSize(myArgumentList,4);

I'm not sure how to do this or even if it is possible to do this?

Any help or suggestions greatly appreciated.

All the Best
Dave









_______________________________________________

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


  • Follow-Ups:
    • Re: Variable Number of Parameters in Method
      • From: "Stephen J. Butler" <email@hidden>
References: 
 >Nav stack creating a bunch of UIImageViews on top of my view (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Nav stack creating a bunch of UIImageViews on top of my view
  • Next by Date: Re: Variable Number of Parameters in Method
  • Previous by thread: Re: Nav stack creating a bunch of UIImageViews on top of my view
  • Next by thread: Re: Variable Number of Parameters in Method
  • Index(es):
    • Date
    • Thread