Objective-C: execute a block or function in a specific NSThread

NSObject

has a method -performSelector:onThread:withObject:waitUntilDone:

that allows you to execute any method on the caller in a specific one NSThread

.

Is there a similar and convenient way to do a C-style function or block in a specific one NSThread

?

+3


source to share


1 answer


The API NSThread

is mostly selector based. In iOS 10 and macOS 10.12, there is a block API for initializing or disconnecting a thread, but not for performing any task in an existing one NSThread

. If you want to use a block based API, you usually use dispatch or work queues, which leaves you out of the weed when managing instances NSThread

yourself.



But if you google "NSThread Block Extension", you will see that there are simple third party APIs to provide block methods for NSThread

. For example GTMNSThread + Blocks.h or NSThread-MCSMAdditions .

+2


source







All Articles