Iphone 将的对象传递给NSThread并继续发送消息?

Iphone 将的对象传递给NSThread并继续发送消息?,iphone,nsthread,Iphone,Nsthread,我能找到的所有关于NSThread的示例/教程,以及我处理它们的唯一方法是使用[NSThread detachNewThreadSelector:@selector(processDataMethod)toTarget:self with Object:nil]将一个方法中的所有处理移动到另一个线程,该线程拥有自己的自动释放池等 这有利于“一枪”操作,该操作只需执行并“消失” 我必须突发性地进行许多小型web服务调用,并且我希望创建一个NSThread对象,该对象在应用程序运行期间保持不变。主要

我能找到的所有关于NSThread的示例/教程,以及我处理它们的唯一方法是使用
[NSThread detachNewThreadSelector:@selector(processDataMethod)toTarget:self with Object:nil]
将一个方法中的所有处理移动到另一个线程,该线程拥有自己的自动释放池等

这有利于“一枪”操作,该操作只需执行并“消失”

我必须突发性地进行许多小型web服务调用,并且我希望创建一个NSThread对象,该对象在应用程序运行期间保持不变。主要是 防止在爆发时产生许多新线程

我查看了
initWithTarget
[NSThread start]
,它似乎处理了我要做的事情。我只是不知道如何把它放在一起,线程是否进入我的对象,我是否将对象传递给线程等等

我试图以伪代码/解释的方式实现这一点:

MyController;

@interface
NSThread *threadProperty; //a property, holding a thread I would like to message
MyWebService *webServiceObject; //the Class that holds web service methods e.g. - (NSArray*) searchFor:(NSString*) searchStr; 

on viewDidLoad:

instantiate webServiceObject;
instantiate threadProperty;
hand threadProperty the webServiceObject.
start the thread. //make it go forever with [[NSRunLoop currentRunLoop] run];

on user does something:
tell the thread to tell the webServiceObject to searchFor:@"Foo";

on thread has a response:
thread says webServiceObject says there are 19 @"Foo" up in the cloud.
我一直在摆弄如何使它工作,但意识到我不明白 这个主题足够好,可以想出一个“模式”来实现它。 我想我是在尝试对一个单独的连续线程中的对象实现一组方法调用,而不是每次需要调用一个特定的方法时都生成一个线程(可能在500毫秒内连续调用8次,然后在2分钟内根本不需要)

我希望这是有意义的,并且在线程方面有一点经验的人可以为我指出正确的方向



这篇文章与我尝试过的非常接近:

我问过一些反模式的方法吗?这通常是在没有人提供帮助的情况下发生的:)