我已經創建了一個NSOperation的自定義子類,並且覆蓋了main
方法。將NSOperation的自定義子類標記爲已終止?
@interface WGTask : NSOperation
@property(readonly) BOOL isExecuting,isFinished;
@end
@implementation WGTask
@synthesize isExecuting,isFinished;
- (void)start {
...
[self willChangeValueForKey:@"isFinished"];
isFinished=YES;
[self didChangeValueForKey:@"isFinished"];
...
}
@end
但是這段代碼引發了一個EXC_BAD_ACCESS錯誤。刪除[self didChangeValueForKey:@"isFinished"]
和[self willChangeValueForKey:@"isFinished"]
可以解決問題,但即使isFinished
值正確更新,NSOperationQueue也不會刪除該操作!
不得不重新讀這幾次到得到它(這也幫助http://stackoverflow.com/questions/3291834/asihttprequest-dealloc-and-exc-bad-access-problem),但我最終發現我的看法是「自動釋放」,這就是爲什麼我得到我的exc_bad_access。 –