Objective c 目标C中的学员仅在特定线程上

Objective c 目标C中的学员仅在特定线程上,objective-c,delegates,Objective C,Delegates,我有两个线程:主线程和工作线程。我希望能够做的是安排对工作线程的回调(委托),而不管是谁调用触发这些委托的函数。例如: /* mainThread */ [Obj asyncCallback]; // triggers callback to delegate foo() /* Worker thread should do all the callback processing. i.e when foo() is called [NSThread currentThread] should

我有两个线程:主线程和工作线程。我希望能够做的是安排对工作线程的回调(委托),而不管是谁调用触发这些委托的函数。例如:

/* mainThread */
[Obj asyncCallback]; // triggers callback to delegate foo()

/* Worker thread should do all the callback processing. i.e when foo() is called [NSThread currentThread] should always give worker threads ID and never main threads ID. */

也许最简单的选择是。您需要确保您的工作线程启动。

我所说的委托是内核生成的,也就是说,我是一些将异步执行的调用。当任务完成时,内核会检查预期的回调是否存在,如果存在,则会通知该回调。我认为performSelector在我的情况下不起作用。您的示例是一条客观的C消息。如果可以执行[obj asyncCallback],则可以执行-performSelector:onThread:waitUntilDone:只要您有一个NSThread对象并且线程处于运行循环中。