Proper NSOperation isCancelled handling
Proper NSOperation isCancelled handling
- Subject: Proper NSOperation isCancelled handling
- From: Alex Curylo <email@hidden>
- Date: Thu, 12 Feb 2009 11:29:08 -0800
So I'm a bit confused about how my NSOperation subclass should
implement the cancel method. The documentation says that "isCancelled"
is a KVO-compliant property. So I figured that calling [super cancel]
ought to take care of that. But it doesn't. Doesn't appear to do
anything, actually, whether I call it or not [self isCancelled] still
returns the expected value in my -start method, but no apparent
isCancelled KVO notification is generated. So I decided to implement
my cancel method as
- (void)cancel
{
// if we have started the operation, cancel it
if (self.downloadConnection)
[self.downloadConnection cancel];
// this generates isExecuting and isFinished notifications as needed
[self sendKVONotifications:nil];
// ok ... what should we do about the isCancelled property?
[self willChangeValueForKey:@"isCancelled"];
[super cancel];
[self didChangeValueForKey:@"isCancelled"];
}
... which just doesn't seem quite right. What's the correct thing to do?
--
Alex Curylo -- email@hidden -- http://www.alexcurylo.com/
"I just can't accept that 24 reserves, 3 hospitalizations and
one fatality are in any way acceptable for what should be the
premier event on the paragliding calendar." -- Mark Hayman
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden