Created
October 25, 2011 17:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id)initWithTitle:(NSString *)title | |
delegate:(id)delegate | |
animationImages:(UIImage *)firstImage, ...NS_REQUIRES_NIL_TERMINATION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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