Current status
I have created a custom NSOperation
object and I want to update some data when it is cancelled.
I've followed what said in this answer and I didn't override the cancel
method.
Here is my header:
// MyOperation.h
@interface MyOperation : NSOperation {
}
@property (nonatomic, retain) OtherDataClass *dataClass;
@end
And the implementation
// MyOperation.m
@implementation MyOperation
@synthesize dataClass;
- (void)main {
if ([self isCancelled]) {
[self.dataClass setStatusCanceled];
NSLog(@"Operation cancelled");
}
// Do some work here
NSLog(@"Working... working....")
[self.dataClass setStatusFinished];
NSLog(@"Operation finished");
}
@end
The question
I have several operations in a queue. I was expecting that, when I call cancelAllOperations
in the queue, I'll get the "Operation cancelled" text in the log and the status updated in my other class but it is not working. The main
method is not being called for the operations in the queue.
Why is this happening and how can I solve it?
Notes
I've tried to overwrite the cancel
method with this:
- (void)cancel {
[super cancel];
[self.dataClass setStatusCanceled];
NSLog(@"Operation cancelled");
}
It is working but I've read that this method should not be overridden.