Re: Implementing Manual KVO For Bitfields Set in Atomic Operations
Re: Implementing Manual KVO For Bitfields Set in Atomic Operations
- Subject: Re: Implementing Manual KVO For Bitfields Set in Atomic Operations
- From: Seth Willits <email@hidden>
- Date: Tue, 21 Aug 2012 09:20:30 -0700
On Aug 21, 2012, at 3:53 AM, Andreas Grosam wrote:
> So, in order to implement KVO, I would need to track changes of the ivar _state, and invoke
> -willChangeValueForKey:, and
> -didChangeValueForKey:
> appropriately.
>
> But, how exactly can I accomplish this with the given code above?
You can call will/did around a change which doesn't actually change the value, so it becomes straightforward.
Also, especially if the number of fields grows, you may want to have a KVC "state" property (not necessarily public), and use
+ (NSSet *)keyPathsForValuesAffectingFoo / Bar; { return [NSSet setWithObject:@"state"]; }
That way you only need to do will/didChangeValueForKey:@"state" and the other KVO methods get triggered as well, instead of having to next multiple will/dids for each key (foo, bar, blah, blah) around every state change.
--
Seth Willits
_______________________________________________
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