Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. - (void)invokeDelegateItemsWithAction:(SEL)action withObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION {
  2. NSMutableArray *deleteItems = [NSMutableArray arrayWithCapacity:0];
  3. NSSet *copySet = [NSSet setWithSet:self.delegateSet];
  4. for (MyDelegateItem *item in copySet) {
  5. if (item.delegate && [item.delegate respondsToSelector:action]) {
  6. NSMethodSignature *sigOfAction = [(id)item.delegate methodSignatureForSelector:action];
  7. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sigOfAction];
  8. [invocation setTarget:item.delegate];
  9. [invocation setSelector:action];
  10.  
  11. if (firstObj) {
  12. NSInteger argsIndex = 2;
  13. va_list args;
  14. va_start(args, firstObj);
  15.  
  16. id argObject = firstObj;
  17. while (argObject) {
  18. if ([argObject isKindOfClass:[NSValue class]]) {
  19. void *value;
  20. [argObject getValue:&value];
  21. [invocation setArgument:&value atIndex:argsIndex];
  22. } else {
  23. [invocation setArgument:&argObject atIndex:argsIndex];
  24. }
  25. argObject = va_arg(args, id);
  26. argsIndex++;
  27. }
  28. va_end(args);
  29. }
  30. [invocation invoke];
  31. }
  32. if (!item.delegate) {
  33. [deleteItems addObject:item];
  34. }
  35. }
  36. for (id obj in deleteItems) {
  37. [self.delegateSet removeObject:obj];
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement