1

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?)

Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • Check this: http://stackoverflow.com/a/10247055/5109911 – Marco Santarossa Aug 13 '16 at 10:27
  • I can't seem t understand your issue, you are trying to pass the block as the "object" param of NSThrad initialization? the object is from "id" type, you can pass anything you desire. – MCMatan Aug 13 '16 at 10:52

1 Answers1

0

Check my answer here. This is the way to proceed I think you have asked the same question twice

Community
  • 1
  • 1
hariszaman
  • 8,202
  • 2
  • 40
  • 59