How do I call performSelectorOnMainThread: with an selector that takes > 1 arguments?

dugla picture dugla · Sep 22, 2009 · Viewed 25.4k times · Source

A typical call to performSelectorOnMainThread: looks like this:

[target performSelectorOnMainThread:action withObject:foo waitUntilDone:NO];

where "result" is an argument passed to "action". A corresponding action would be:

- (void)doSomethingWithThing1:(id *)thing1

What is the correct syntax for calling an action that takes > 1 argument? Such as:

- (void)doSomethingWithThing1:(id *)thing1 andThing2(id *)thing2 andAlsoThing3(id *)thing3

[target performSelectorOnMainThread:action withObject:??? waitUntilDone:NO];

Answer

coneybeare picture coneybeare · Sep 22, 2009

You can do it by putting your args in a dictionary or array and passing that to a special function

- (void)doStuff:(NSString *)arg1 and:(NSString *)arg2 and:(NSString *)arg3 {
...
}

- (void)doStuff:(NSArray *)argArray {
    [self doStuff:[argArray objectAtIndex:0]
              and:[argArray objectAtIndex:1]
              and:[argArray objectAtIndex:2];
}