On Oct 6, 2011, at 9:16 AM, Torsten Curdt wrote:
> Hm... using KVO for an object to observe it's own properties?
> That's feels wrong to me.
> Is that just me?

You could factor the observing out into a separate object.

I'm just rattling this idea off the top of my head, so it might be flawed (if 
not outright nuts), but... you could have a class called MyDisplayTickler with 
a global shared instance. It observes a fake view property called 
myNeedsDisplay.

Here is a totally untested MyDisplayTickler class, plus a category on NSView:

<https://gist.github.com/1267594>

With these in place, your view class does three trivial things:

* In its init, it does [[MyDisplayTickler sharedInstance] 
startObservingView:self].

* In its dealloc, it does [[MyDisplayTickler sharedInstance] 
stopObservingView:self].

* It implements +propertiesThatTriggerDisplay, something like this:

+ (NSArray *)propertiesThatTriggerDisplay
{
    return [NSArray arrayWithObjects:
            @"titleColor",
            @"fontForHighScore",
            @"selectedShape",  // etc.
            nil];
}

What do you all think? I've run into the problem Torsten describes and would 
like to think there's *some* better solution than writing setters.

--Andy

_______________________________________________

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

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

Reply via email to