Skip to content

Instantly share code, notes, and snippets.

@larsacus
Created October 25, 2011 17:30
Show Gist options
  • Save larsacus/1313585 to your computer and use it in GitHub Desktop.
Save larsacus/1313585 to your computer and use it in GitHub Desktop.
Enumerate a list of object specified in a prototype with NS_REQUIRES_NIL_TERMINATION. From http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html
- (id)initWithTitle:(NSString *)title
delegate:(id)delegate
animationImages:(UIImage *)firstImage, ...NS_REQUIRES_NIL_TERMINATION;
- (id)initWithTitle:(NSString *)title delegate:(id)delegate animationImages:(UIImage *)firstImage, ...{
if ((self = [super initWithFrame:CGRectZero])) {
va_list args;
va_start(args, firstImage);
NSMutableArray *images = [[NSMutableArray alloc] init];
for (UIImage *arg= firstImage; arg != nil; arg = va_arg(args, UIImage*)) {
[images addObject:arg];
}
_title = [title copy];
_animationImages = [images copy];
_delegate = delegate; //weak assign
_visible = NO;
va_end(args);
[images release], images = nil;
}
return self;
}
NewObject *new = [[NewObject alloc] initWithTitle:@"Loading..."
delegate:self
animationImages:[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"], nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment