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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to