On Oct 15, 2013, at 13:43 , Todd Heberlein <todd_heberl...@mac.com> wrote:

> I have an AppDelegate with several ivars that need to be changed by code 
> running out of dispatch queues. Should the setting of these values (because 
> of KVO maybe?) be done by putting a block on dispatch_get_main_queue() and 
> change the ivar there? For example, is the following
> 
> dispatch_async(dispatch_get_main_queue(), ^{
>       self.some_ivar = some_value;
> });
> 
> the right design pattern?

That's a simple, safe way to do it. I don't think KVO requires you to do things 
on the main thread, but I believe all the notifications will happen on whatever 
thread caused the change (so, for example, if you have an element in your UI 
update via KVO, the update to the value should be done on the main thread).

The other thing to keep in mind is synchronization. Always updating the 
property via the main queue is a good way to ensure there are no concurrency 
issues.

-- 
Rick



Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________

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