Objective c 运行类的NSThread

Objective c 运行类的NSThread,objective-c,multithreading,Objective C,Multithreading,我在互联网上找到的每一个例子(包括Apple doc)都将目标设定为如下自我: [NSThread detachNewThreadSelector:@selector(threadedTask) toTarget:self withObject:nil]; Task *task = [[Task alloc] init]; [NSThread detachNewThreadSelector:@selector(main) toTarget:task withObject:nil]; 由于我想

我在互联网上找到的每一个例子(包括Apple doc)都将目标设定为如下自我:

[NSThread detachNewThreadSelector:@selector(threadedTask) toTarget:self withObject:nil];
Task *task = [[Task alloc] init];
[NSThread detachNewThreadSelector:@selector(main) toTarget:task withObject:nil];
由于我想在后台执行更复杂的任务(涉及多个方法),我考虑创建一个类
task
,如下所示:

[NSThread detachNewThreadSelector:@selector(threadedTask) toTarget:self withObject:nil];
Task *task = [[Task alloc] init];
[NSThread detachNewThreadSelector:@selector(main) toTarget:task withObject:nil];
但是我想知道,我的类
任务
的实例变量将如何处理?在我的方法
main
中,我是否可以使用
[self myMethod]
安全地调用类
任务的方法并修改成员变量(假设我是唯一访问它的线程)

这种处理线程的方式对我来说似乎很奇怪,如果我的问题很愚蠢,请原谅^^


提前感谢

如果每个
任务只有一个
NSThread
(包括主线程),那么是的,您可以做任何您想做的事情。一旦多个线程可以同时访问某些数据,您就必须提供同步。

谢谢!所以我会立即尝试,然后我会接受你的回答(因为stackoverflow迫使我等待接受^)