• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
kvo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>
  • Prev by Date: Re: Is it possible to create a Finder-like icon in Dock?
  • Next by Date: Re: kvo
  • Previous by thread: Re: Animating a NSProgressIndicator
  • Next by thread: Re: kvo
  • Index(es):
    • Date
    • Thread