While it wouldn't be hard to spin up my own method for this, it wouldn't be as efficient as
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait;
is there a built-in method to do this with blocks?
If not, is there a way I can avoid creating an object, putting the block on it, and passing it to a selector method? I also wonder if there would be problems with data accessed within the block...
The blocks equivalent to the performSelector: method is CFRunLoopPerformBlock — you just need to get a reference to that thread's CFRunLoop.
Have a look at Apple's documentation for the function and note the caveat in the discussion — you'll probably want to call CFRunLoopWakeUp afterwards so the block is executed right away.
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