oc 可变參数传递

时间:2023-03-08 17:04:06
oc 可变參数传递

- (id)initWithFrame:(CGRect)frame delegate:(id<SGFocusImageFrameDelegate>)delegate focusImageItems:(SGFocusImageItem *)firstItem, ...
{
self = [super initWithFrame:frame];
if (self) {
NSMutableArray *imageItems = [NSMutableArray array];
SGFocusImageItem *eachItem;
va_list argumentList;
if (firstItem)
{
[imageItems addObject: firstItem];
va_start(argumentList, firstItem);
while((eachItem = va_arg(argumentList, SGFocusImageItem *)))
{
[imageItems addObject: eachItem];
}
va_end(argumentList);
} objc_setAssociatedObject(self, (const void *)SG_FOCUS_ITEM_ASS_KEY, imageItems, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
_isAutoPlay = YES;
[self setupViews]; [self setDelegate:delegate];
}
return self;
}