Re: adding something to a setter
Re: adding something to a setter
- Subject: Re: adding something to a setter
- From: Andy Lee <email@hidden>
- Date: Thu, 06 Oct 2011 18:23:10 -0400
On Oct 6, 2011, at 4:12 PM, Kyle Sluder wrote:
> On Thu, Oct 6, 2011 at 12:33 PM, Quincey Morris
> <email@hidden> wrote:
[...]
>> Note, however, that because the observer mechanism is so clunky, you're going to write *more* lines of code this way than in overriding the setter, yet all it buys you is the unwanted/unnecessary "atomic" implementation.
>
> Not necessarily. If you expect subclasses to add properties that
> require poking -setNeedsDisplay:, or you just have a lot of them, it's
> probably worth adding a class method like +keyPathsRequiringRedisplay,
> register as self-observers for all these keypaths, and provide a
> really simple implementation of -observeValueForKeyPath:… that calls
> [self setNeedsDisplay].
This is what the code I dashed off this morning does (or at least intends to do), except it puts the clunky KVO code into a separate convenience class that you can drop into any project.
I just now cleaned up some silly mistakes and stole Kyle's "keyPathsRequiringRedisplay" name, though it still isn't perfect (see the description) and totally untested.
<https://gist.github.com/1267594>
--Andy
_______________________________________________
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