NSOperationサブクラスでは、長いループの先頭で、またはサブクラスのメソッドの長いメソッド(Core Data Fetches、配列の並べ替えなど)の前にキャンセルをチェックしますmain
。以下の例を参照してください。
-(void)main{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for( int i=0; i< 100; i++ )
{
//Check for cancellation
if( [self isCancelled] ){
[pool drain];
return;
}
//Do the work
}
[pool drain];
}
プールを空にし、できるだけ早くメソッドを終了する以外に、他にすべきことはありますか?