Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSThread with class method?

Tags:

cocoa

nsthread

Is it possible to run a class method (starting with a '+') in a separate thread? Normally I call the method like [myClass myController]; I tried [NSThread detachNewThreadSelector:myController toTarget:myClass withObject:nil]; without success.

like image 510
Jeroen Sterckx Avatar asked Dec 29 '22 21:12

Jeroen Sterckx


1 Answers

Yes, you just need to make the target [myClass class] instead of myClass. Also you forgot to use @selector() around the selector name. So you want:

[NSThread detachNewThreadSelector:@selector(myController) toTarget:[myClass class] withObject:nil];

like image 163
Nick Moore Avatar answered Feb 05 '23 07:02

Nick Moore