Call a function using thread in xcode

I created a stream in xcode, and I gave the name of the function that is called from this stream. but my problem is that the name of the function that is called to call is not called (found out when I set a breakpoint in this function)

the code:

 NSThread* myThread; 
 [myThread start]; 
 [self performSelector:@selector(func1:) onThread:myThread withObject:nil waitUntilDone:false]

and later I tried this as well:

NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(func1:)object:nil];
[myThread start]; 

above, func1 is the name of the function being called.

so can someone tell me how to create a thread and call func1 from there ....

+5
source share
3 answers

, . myThread, start, , start nil. performSelector:onThread:withObject:waitUntilDone:, , -, .

, - performSelector:onThread:withObject:waitUntilDone:.

, , , performSelectorInBackground:withObject:. :

[self performSelectorInBackground:@selector(func1:) withObject:nil];
+16

:

[NSThread detachNewThreadSelector:@selector(func1) toTarget:self withObject:nil];

- "func1" (: ), ":" .

+3

If your func1 takes one argument. Then definitely it should work with the second approach that you used. Maybe your fuc1 has no formal argument and is still called in a selector like this @selector (fuc1 :) and the object is passed as zero. therefore for this reason it does not work. This may be one of the reasons. just try if not.

0
source

All Articles