2

I want to perform the method which has a few arguments. Is there any easy way to pass a few of them at once? Something like

[self performSelector:@selector(methodName) withObject:firstParameter withObject:secondParameter afterDelay:0.1];

I've found a way here SEL performSelector and arguments, but it seems a little bit complicated and I guess there should be some easier way to make it done. But probably it just looks like that to me because of being newbie in Objective C :)

I'll appreciate your help a lot!

Community
  • 1
  • 1
Solomiya
  • 310
  • 4
  • 15

2 Answers2

3

Or another solution:

#import <objc/runtime.h>
...
objc_msgSend(self, sel_getUid("methodwithFirstParam:secondParam:thirdParam:"), @"foo", "bar", 42 );

Unlike performSelector:, method objc_msgSend can take a lot of parameters with different types, like NSObject (and child classes) or BOOL, int, char* etc.

Kevin Bedell
  • 13,254
  • 10
  • 78
  • 114
AlexDenisov
  • 4,022
  • 25
  • 31
3
  1. Wrap your parameters into NSDictionary and send this dictionary as parameter.
  2. Make custom class and include all your parameters in this class as properties. Send this newly created object as parameter.
beryllium
  • 29,669
  • 15
  • 106
  • 125