NSObject has a method -performSelector:onThread:withObject:waitUntilDone: that allows executing any method on the calling object in a specific NSThread.
Is there a similar and convenient way to execute a C-style function or block in a specific NSThread?
The NSThread API is largely selector-based. In iOS 10 and macOS 10.12, there is block-based API for the initializing or detaching of the thread, but not for performing some task on an existing NSThread. If you want to use block-based API, you'd generally use dispatch or operation queues, which gets you out of the weeds of managing NSThread instances yourself.
But if you google "NSThread block extension", you'll see there are simple third-party APIs to provide block methods for NSThread. E.g., GTMNSThread+Blocks.h or NSThread-MCSMAdditions.
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