kvo
kvo
- Subject: kvo
- From: Ariel Feinerman <email@hidden>
- Date: Tue, 14 Jun 2011 03:52:06 +0300
Hi,
how to cancel operation which is performing?
I think it is not safe:
- (void) beginOperation {
[_operation cancel];
_operation = [[Operation alloc] initWithURL: [NSURL URLWithString: @"
http://rss.cnn.com/rss/cnn_topstories.xml"]];
_queue = [NSOperationQueue new];
[_operation addObserver: self forKeyPath: @"isFinished" options:
NSKeyValueObservingOptionNew context: NULL];
[_operation addObserver: self forKeyPath: @"isCancelled" options:
NSKeyValueObservingOptionNew context: NULL];
[_queue addOperation: _operation];
}
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object
change: (NSDictionary *) change context: (void *) context {
if ([keyPath isEqualToString: @"isFinished"]) {
if ([[change valueForKey: NSKeyValueChangeNewKey] boolValue]) {
[rootViewController performSelectorOnMainThread: @selector(setItemList:)
withObject: [_operation itemList] waitUntilDone: NO];
static BOOL firstTime = YES;
if (firstTime) {
[self performSelectorOnMainThread: @selector(setRootView:) withObject: nil
waitUntilDone: NO];
firstTime = NO;
}
}
}
else if ([keyPath isEqualToString: @"isCancelled"]) {
if ([[change valueForKey: NSKeyValueChangeNewKey] boolValue]) {
if ([_operation error]) {
[self performSelectorOnMainThread: @selector(errorOccurs:) withObject:
[_operation error] waitUntilDone: NO];
}
}
}
[_operation removeObserver: self forKeyPath: @"isFinished"];
[_operation removeObserver: self forKeyPath: @"isCancelled"];
[_operation release];
_operation = nil;
[_queue release];
_queue = nil;
}
--
best regards
Ariel
_______________________________________________
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
- Follow-Ups:
- Re: kvo
- From: Ken Tozier <email@hidden>