Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)invokeDelegateItemsWithAction:(SEL)action withObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION {
- NSMutableArray *deleteItems = [NSMutableArray arrayWithCapacity:0];
- NSSet *copySet = [NSSet setWithSet:self.delegateSet];
- for (MyDelegateItem *item in copySet) {
- if (item.delegate && [item.delegate respondsToSelector:action]) {
- NSMethodSignature *sigOfAction = [(id)item.delegate methodSignatureForSelector:action];
- NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sigOfAction];
- [invocation setTarget:item.delegate];
- [invocation setSelector:action];
- if (firstObj) {
- NSInteger argsIndex = 2;
- va_list args;
- va_start(args, firstObj);
- id argObject = firstObj;
- while (argObject) {
- if ([argObject isKindOfClass:[NSValue class]]) {
- void *value;
- [argObject getValue:&value];
- [invocation setArgument:&value atIndex:argsIndex];
- } else {
- [invocation setArgument:&argObject atIndex:argsIndex];
- }
- argObject = va_arg(args, id);
- argsIndex++;
- }
- va_end(args);
- }
- [invocation invoke];
- }
- if (!item.delegate) {
- [deleteItems addObject:item];
- }
- }
- for (id obj in deleteItems) {
- [self.delegateSet removeObject:obj];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement