Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. + (TTSectionedDataSource*)dataSourceWithObjects:(id)object,... {
  2.  
  3. #import <Cocoa/Cocoa.h>
  4.  
  5. @interface NSMutableArray (variadicMethodExample)
  6.  
  7. - (void) appendObjects:(id) firstObject, ...; // This method takes a nil-terminated list of objects.
  8.  
  9. @end
  10.  
  11. @implementation NSMutableArray (variadicMethodExample)
  12.  
  13. - (void) appendObjects:(id) firstObject, ...
  14. {
  15. id eachObject;
  16. va_list argumentList;
  17. if (firstObject) // The first argument isn't part of the varargs list,
  18. { // so we'll handle it separately.
  19. [self addObject: firstObject];
  20. va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
  21. while (eachObject = va_arg(argumentList, id)) // As many times as we can get an argument of type "id"
  22. [self addObject: eachObject]; // that isn't nil, add it to self's contents.
  23. va_end(argumentList);
  24. }
  25. }
Add Comment
Please, Sign In to add comment