• 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
Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:


  • Subject: Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
  • From: Gilles Celli <email@hidden>
  • Date: Thu, 24 Apr 2014 21:17:05 +0200

Ok thank you very much for the clarification, it's much clearer now for me.
So I will stick with KVO, as you wrote.

Cheers,


Gilles

On 24 avr. 2014, at 19:38, Quincey Morris <email@hidden> wrote:

> On Apr 24, 2014, at 06:47 , Gilles Celli <email@hidden> 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 (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


References: 
 >NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath: (From: Gilles Celli <email@hidden>)
 >Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath: (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
  • Next by Date: Re: Good idea/bad idea?
  • Previous by thread: Re: NSOperation - Update UI with delegate or in a Controller with oberseValueForKeyPath:
  • Next by thread: Good idea/bad idea?
  • Index(es):
    • Date
    • Thread