• 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: no fixed variable parameter preceding a variable ... parameter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: no fixed variable parameter preceding a variable ... parameter?


  • Subject: Re: no fixed variable parameter preceding a variable ... parameter?
  • From: Ben Dougall <email@hidden>
  • Date: Sun, 26 Oct 2003 14:02:38 +0000

here's how to pass and extract a variable number of objects without using an array to pass them, jic anyone's interested:


calling example:
TestClass *test = [[TestClass alloc] init];
NSString *anObject = [[NSString alloc] initWithString:@"any type"];
NSString *another = [[NSString alloc] initWithString:@"of objects"];
[test passVariableNumberOfObjects: anObject, another, @"and another", nil]; // must be objects and list terminated with nil



#import "TestClass.h"
@implementation TestClass
- (void)passVariableNumberOfObjects:(id)firstObject, ...
{
NSMutableArray *passedObjects;
if( firstObject != NULL ) {
id tmp;
passedObjects = [[NSMutableArray alloc] init];
[passedObjects addObject: firstObject ];
va_list arglist;
va_start(arglist, firstObject);
while( tmp = va_arg(arglist, id) )
[passedObjects addObject: tmp ];
va_end(arglist);
// can do whatever with passed objects which are in the passedObjects array now
NSLog(@"%@", passedObjects);
[passedObjects release];
} else
NSLog(@"no objects passed");
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Re: no fixed variable parameter preceding a variable ... parameter? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: [OT] Panther's Mail.app
  • Next by Date: The Problems with NSController
  • Previous by thread: Re: no fixed variable parameter preceding a variable ... parameter?
  • Next by thread: Re: no fixed variable parameter preceding a variable ... parameter?
  • Index(es):
    • Date
    • Thread