• 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: indeterminate number of arguments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indeterminate number of arguments


  • Subject: Re: indeterminate number of arguments
  • From: Sherm Pendley <email@hidden>
  • Date: Wed, 16 Feb 2011 18:29:03 -0500

On Wed, Feb 16, 2011 at 6:26 PM, Sherm Pendley <email@hidden> wrote:
> On Wed, Feb 16, 2011 at 6:12 PM, Todd Heberlein <email@hidden> wrote:
>> I see methods like this one (for NSArray) with an indeterminate number of arguments
>>
>>        - (id)initWithObjects:(id)firstObj, ...
>>
>> How can I declare my own method like this
>
> Just like above, with ..., as in:
>
> - (id) initWithObjects:(id)firstObject, ...;
>
>> and how, in the implementation, do I access the set of arguments passed in?
>
> Using the va_* macros found in stdarg.h. For example:
>
> - (id) initWithObjects:(id)firstObject, ... {
>    va_list args;
>    id nextObject;
>    NSMutableArray *arr = [NSMutableArray arrayWithObject:firstObject];
>
>    va_start(args, firstObject);
>    while (nextObject = va_arg(args, id)) {
>        [arr addObject:nextObject];
>    }
>
>    va_end(args);
> }

Ignoring, of course, that the example I gave is a very badly-written
initializer that doesn't call [super init] or return self. Please
focus on the use of the va_* macros. :-\

sherm--

--
Cocoa programming in Perl:
http://camelbones.sourceforge.net
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: indeterminate number of arguments
      • From: Mark Wagner <email@hidden>
References: 
 >indeterminate number of arguments (From: Todd Heberlein <email@hidden>)
 >Re: indeterminate number of arguments (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: indeterminate number of arguments
  • Next by Date: Re: indeterminate number of arguments
  • Previous by thread: Re: indeterminate number of arguments
  • Next by thread: Re: indeterminate number of arguments
  • Index(es):
    • Date
    • Thread