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.
Asked
Active
Viewed 1,072 times
4

skaffman
- 398,947
- 96
- 818
- 769

Jeroen Sterckx
- 43
- 3
1 Answers
10
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];

Nick Moore
- 15,547
- 6
- 61
- 83
-
Thank you. The @selector part was a typo sorry. Works perfectely. – Jeroen Sterckx Apr 02 '10 at 17:05
-
I am also doing same. But my method is being called twice – Ravee10 Oct 24 '15 at 13:47
-
You should ask a new question @Ravee10, with the specific details of your problem – Nick Moore Nov 20 '15 at 11:39