In a current iOS app I am using this perform selector approach:
[self performSelector:@selector(doSomething)
onThread:myThread
withObject:nil
waitUntilDone:NO
modes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
I am not sure how to make a selector run on a specific thread in swift. Any suggestions?
As I suggested in comment, you shouldn't manage threads any more. Always use dispatch_queue instead of threads.
If you somehow really want to do it, here is a workaround: CFRunLoopPerformBlock.
This is C code, but I think you can translate it to Swift code without too much work.
// worker thread
CFRunLoopRef myrunloop; // some shared variable
void worker_thread_main() {
myrunloop = CFRunLoopGetCurrent();
CFRunLoopRun(); // or other methods to run the runloop
}
// other thread to schedule work
CFRunLoopPerformBlock(myrunloop, kCFRunLoopCommonModes, ^{
dowork();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With