1
在我的NSOperation子類中,我檢查在長度循環頂部的取消,或在子類的main
方法中的任何長度方法(核心數據獲取,數組排序等)之前取消。看下面的例子。NSOperation最佳實踐,迴應取消
-(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];
}
除了排水池和儘快退出方法之外,還有什麼我應該做的嗎?