问题
I have a function which takes a block as parameter:
typedef void (^ MyCallBack)(int);
-(void)doTask:(MyCallBack)callback{
...
}
I need to run the function in another thread with NSThread
:
NSThread* myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(doTask:)
object:nil]; //how to pass callback block here?
[myThread start];
But how can I have the callback passed in the NSThread initialisation function above? Is it possible?
(If it is impossible, what could be the good alternative to achieve the same?)
回答1:
Check my answer here. This is the way to proceed I think you have asked the same question twice
来源:https://stackoverflow.com/questions/38931737/initialize-start-nsthread-with-target-selector