Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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];
like image 574
dugla Avatar asked Sep 22 '09 14:09

dugla


1 Answers

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];
}
like image 120
coneybeare Avatar answered Sep 28 '22 11:09

coneybeare