• 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: adding something to a setter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: adding something to a setter


  • Subject: Re: adding something to a setter
  • From: Andy Lee <email@hidden>
  • Date: Thu, 06 Oct 2011 10:55:17 -0400

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 (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

  • Follow-Ups:
    • Re: adding something to a setter
      • From: Andy Lee <email@hidden>
References: 
 >adding something to a setter (From: Torsten Curdt <email@hidden>)
 >Re: adding something to a setter (From: Stephan Michels <email@hidden>)
 >Re: adding something to a setter (From: Torsten Curdt <email@hidden>)

  • Prev by Date: Re: NSArrayController Selection and Managed Object Context Undo
  • Next by Date: Re: adding something to a setter
  • Previous by thread: Re: adding something to a setter
  • Next by thread: Re: adding something to a setter
  • Index(es):
    • Date
    • Thread