Ссылка на класс NSThread
Пример запуска дочернего потока:
- (void)threadRun
{
// One thread, one autorelease pool. as main thread's pool inside main.c
NSAutoreleasePool *aPool = [[NSAuroreleasePool alloc] init];
// do-job in thread here
[aPool release];
}
- (void)performJobWithThread
{
// Method 1:
NSThread *aThread = [[NSThread alloc] initWithTarget:self
selector:@selector(threadRun)
object:nil];
[aThread start];
/// Release aThread at some point avoid memory leak.
// Method 2:
[NSThread detachNewThreadSelector:@selector:@selector(threadRun)
toTarget:self
withObject:nil];
}
Перед использованием NSThread лучше прочитать Руководство по программированию потоков первый.Он расскажет вам об управлении памятью, взаимодействии с другим потоком, ... и т. Д.
NSOperation и NSOperationQueue хороши для проектирования многопоточности.Но я изучаю их сейчас и не могу говорить о них ясно.