• 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: Variadic arguments to methods in Objective-C - How ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Variadic arguments to methods in Objective-C - How ?


  • Subject: Re: Variadic arguments to methods in Objective-C - How ?
  • From: Vincent Coetzee <email@hidden>
  • Date: Sat, 8 Jan 2005 22:50:32 +0200

Specifically I was extending NSArray as follows

@implementation NSArray (NSArrayExtensions)

+ (NSArray*) arrayWithInts: (int) count,...
    {
    va_list                ap;
    NSMutableArray*        array;
    int                    index;

    array = [[[NSMutableArray alloc] init] autorelease];
    va_start(ap,count);
    for (index=0;index<count;index++)
        {
        [array addObject: [NSNumber numberWithInt: *((int*)ap)]];
        va_arg(ap, int);
        }
    va_end(ap);
    return(array);
    }

@end

works like a charm, altho if there is a better way to do this I am all ears !

Thanks

Vincent

On Jan 08, 2005, at 22:22, Andreas Mayer wrote:




Am 8. Jan 2005 um 20:38 Uhr schrieb Vincent Coetzee:


So can I use the normal C mechanism and if not how is it done ?


Usually you just use an NSArray or NSDictionary and populate it with the arguments.


- (void)doSomethingWithLotsOfArgumentsFromArray:(NSArray *)theArguments
{
    id argumentOne = [theArguments objectAtIndex:0];
    ...
}

[yourObject doSomethingWithLotsOfArgumentsFromArray:[NSArray arrayWithObjects:@"one", @"two", nil]];


Andreas

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40wallflower.co.za


This email sent to email@hidden




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Variadic arguments to methods in Objective-C - How ?
      • From: Andreas Mayer <email@hidden>
References: 
 >Variadic arguments to methods in Objective-C - How ? (From: Vincent Coetzee <email@hidden>)
 >Re: Variadic arguments to methods in Objective-C - How ? (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: Variadic arguments to methods in Objective-C - How ?
  • Next by Date: Re: Continuous controls and undo
  • Previous by thread: Re: Variadic arguments to methods in Objective-C - How ?
  • Next by thread: Re: Variadic arguments to methods in Objective-C - How ?
  • Index(es):
    • Date
    • Thread