j'ai une fonction qui prend un bloc en tant que paramètre:initialiser et commencer NSThread avec la cible et sélecteur
typedef void (^ MyCallBack)(int);
-(void)doTask:(MyCallBack)callback{
...
}
Je dois exécuter la fonction dans un autre thread avec NSThread
:
NSThread* myThread = [[NSThread alloc] initWithTarget:self
selector:@selector(doTask:)
object:nil]; //how to pass callback block here?
[myThread start];
Mais comment puis-je avoir le callback passé dans la fonction d'initialisation NSThread ci-dessus? C'est possible?
(S'il est impossible, ce qui pourrait être la bonne alternative pour obtenir le même?)
Cochez ceci: http://stackoverflow.com/a/10247055/5109911 –
Je n'arrive pas à comprendre votre problème, vous essayez de passer le bloc comme param "object" de l'initialisation de NSThrad? l'objet est de type "id", vous pouvez passer tout ce que vous désirez. – MCMatan