initialize & start NSThread with target & selector

空扰寡人 提交于 2019-12-11 06:29:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!