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

Re: Variable Number of Parameters in Method


  • Subject: Re: Variable Number of Parameters in Method
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Wed, 21 Aug 2013 12:17:09 -0500

On Wed, Aug 21, 2013 at 4:22 AM, Dave <email@hidden> wrote:

>         if ([myType isEqualToString:@"NSInteger"] )
>                 {
>                 myNSInteger = va_arg(myArgumentList,NSInteger*);
> //  do something with myNSInteger
>                 [myFormattedString appendFormat:@"myNSInteger = %d ",
> myNSInteger];
>                 }
>
>         else if ([myType isEqualToString:@"CGFloat"] )
>                 {
>                 myCGFloat = va_arg(myArgumentList, CGFloat*);
> //  do something with myCGFloat
>                 [myFormattedString appendFormat:@"myCGFloat = %f ",
> myCGFloat];
>                 }


This is better, however... if you pass an actual NSInteger or CGFloat to
the method, va_arg() should have a type of NSInteger or CGFloat, not
pointers to those types. Your code examples with it's printf style formats
is using the former, not the latter. Just to be clear, you can have all
these cases:

if ([myType isEqualToString:@"NSInteger"] ) {
   myNSInteger = va_arg(myArgumentList,NSInteger);
} else if ([myType isEqualToString:@"NSInteger*"] ) {
  pMyNSInteger = va_arg(myArgumentList,NSInteger*);
} else if ([myType isEqualToString:@"CGFloat"]) {
  myCGFloat = va_arg(myArgumentList, CGFloat);
} else if ([myType isEqualToString:@"CGFloat*"]) {
  pMyCGFloat = va_arg(myArgumentList, CGFloat*);
} ... etc
_______________________________________________

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: Alex Zavatone <email@hidden>
References: 
 >Nav stack creating a bunch of UIImageViews on top of my view (From: Rick Mann <email@hidden>)
 >Variable Number of Parameters in Method (From: Dave <email@hidden>)
 >Re: Variable Number of Parameters in Method (From: "Stephen J. Butler" <email@hidden>)
 >Re: Variable Number of Parameters in Method (From: Dave <email@hidden>)

  • Prev by Date: Don't worry - Fixed - Compiler Error on Class Method?
  • Next by Date: Re: Drawing after CGContextClosePath() still appends line
  • Previous by thread: Re: Variable Number of Parameters in Method
  • Next by thread: Re: Variable Number of Parameters in Method
  • Index(es):
    • Date
    • Thread