On Apr 24, 2014, at 06:47 , Gilles Celli <gilles.ce...@ecgs.lu> wrote:

> 1. With KVO in a Controller object: Observing the NSOperation's "isFinished" 
> value and then in observeValueForKeyPath:ofObject:change:context:
>    update the UI (graph display) on the main thread with  
> performSelectorOnMainThread:withObject:waitUntilDone
> 
> 2. No KVO: in NSOperation the UI is updated after the parsing is done, by 
> calling the delegate again with
>    performSelectorOnMainThread:withObject:waitUntilDone
> 
> I've tested both approaches but can't decide which one is the most correct / 
> best, or what are the benefits of using one approach or another ?

There’s no absolute answer to this, but I’d choose #1, for a couple of reasons:

— It means the parsing code doesn’t have to know how it’s being “watched” or by 
whom or for what purpose. Other “watchers” can be added later, if necessary, 
without having to intervene in the parsing or delegate code.

— It avoids turning the delegate into a dumping ground for miscellaneous 
functionality.

Note that it’s not absolutely necessary to use a delegate for #2. You can do:

        [self performSelectorOnMainThread:@selector(operationAsciiParsingDone:)
                                          withObject:[self parsedAscii]  
waitUntilDone:NO];

So long as ‘operationAsciiParsingDone:’ doesn’t try to access any of the 
object’s internal data structures (which a delegate wouldn’t have been able to 
do anyway), this is thread-safe, odd as it might seem at first. (More 
accurately, it’s exactly as thread safe as using a delegate.)

_______________________________________________

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

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

Reply via email to