NSThread 백그라운드 쓰레드 돌리기

By | 2009년 12월 23일

프로그래밍을 하다 보면 느끼겠지만 쓰레드는 필수이다.

iPhone에서 백그라운드쓰레드를 돌려보자..

Objective-c 에서는 NSThread 라는 클래스가 있다.

일단 쓰레드 처리할 함수를 만든다.


-(void) myTestThread:(id)anObject {

     NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
     //이곳에 처리할 코드를 넣는다.
    
    [autoreleasepool release];
    [NSThread exit];

}

그리고 쓰레드를 호출한다.

[NSThread detachNewThreadSelector:@selector(myTestThread:) toTarget:self withObject:nil];

간단~