Solomiya
Solomiya

Reputation: 320

performSelector with a few parameters

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!

Upvotes: 2

Views: 490

Answers (2)

AlexDenisov
AlexDenisov

Reputation: 4117

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.

Upvotes: 3

beryllium
beryllium

Reputation: 29767

  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.

Upvotes: 3

Related Questions