views:

153

answers:

1

Hello guys!

I am creating a MyOperation object (inherited from NSOperation) and add to a NSOperationQueue. Then I am doing KVO on MyOperation. I am using this method

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;

to get a value from MyOperation if it is finished. In this method I am using a convenience method from an other class to get some other data.

Maybe here synchronization problems in the observeValue... method?

A: 

I don't know your use-case, but using KVO for threads/operations isn't wise.

You could instead have your Operation object post a notification once it's complete. Or alternatively define a delegate protocol and give your Operation a delegate... you can then define some kind of 'myOperationComplete:' method which is invoked by your Operation against the delegate it was given, using performSelectorOnMainThread.

dannywartnaby
Everything is working well with KVO. I just want the issues if there are any. You said there are some issues. Can you point it out which are those?
Infinity
The operation may be cancelled before the "main" is called. So posting a notification involves some extra work in some cases.
Felix