Altering the behavior of NSUserDefaults

  • Folks,

    I've run into a bit of a problem, which I'm unsure how to address.

    I'm implementing a preferences panel in my application, with the view
    objects bound to an NSUserDefaultsController.

    Many of the bindings need to be handled programatically - for
    instance, the "enabled" bindings depend on the value of some of the
    other settings.

    The problem is, I can't figure out how, or where, I'm supposed to
    instantiate my subclass of NSUserDefaults (or of
    NSUserDefaultsController, for that matter).

    I tried setting the NSUserDefaultsController's custom class attribute
    in Interface Builder, but it seems to be ignored, when creating
    controllers (Is this a bug in IB? or am I not supposed to be
    overriding the behavior of controllers?)

    I also tried setting a delegate for NSUserDefaults, but that doesn't
    appear to be supported.

    Any suggestions?

    Ron Aldrich
    Software Architects, Inc.
  • On Fri, 6 Oct 2006 16:41:15 -0700, Ron Aldrich <raldrich...> said:
    > Folks,
    >
    > I've run into a bit of a problem, which I'm unsure how to address.
    >
    > I'm implementing a preferences panel in my application, with the view
    > objects bound to an NSUserDefaultsController.
    >
    > Many of the bindings need to be handled programatically - for
    > instance, the "enabled" bindings depend on the value of some of the
    > other settings.
    >
    > The problem is, I can't figure out how, or where, I'm supposed to
    > instantiate my subclass of NSUserDefaults (or of
    > NSUserDefaultsController, for that matter).
    >
    > I tried setting the NSUserDefaultsController's custom class attribute
    > in Interface Builder, but it seems to be ignored, when creating
    > controllers (Is this a bug in IB? or am I not supposed to be
    > overriding the behavior of controllers?)
    >
    > I also tried setting a delegate for NSUserDefaults, but that doesn't
    > appear to be supported.
    >
    > Any suggestions?

    What I would do is to bind stuff in the preferences panel to a custom class,
    and bind the stuff in the custom class to the NSUserDefaults. That way,
    there is no need for a subclass of NSUserDefaults; the functionality you're
    looking for would be handled by the intermediate class. Binding "chains" of
    this sort are quite common in my apps, because I often have three (or more)
    things to keep in synch. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • On Fri, 06 Oct 2006 17:07:00 -0700, Matt Neuburg <matt...> said:
    > On Fri, 6 Oct 2006 16:41:15 -0700, Ron Aldrich <raldrich...>  said:
    >> Folks,
    >>
    >> I've run into a bit of a problem, which I'm unsure how to address.
    >>
    >> I'm implementing a preferences panel in my application, with the view
    >> objects bound to an NSUserDefaultsController.
    >>
    >> Many of the bindings need to be handled programatically - for
    >> instance, the "enabled" bindings depend on the value of some of the
    >> other settings.
    >>
    >> The problem is, I can't figure out how, or where, I'm supposed to
    >> instantiate my subclass of NSUserDefaults (or of
    >> NSUserDefaultsController, for that matter).
    >>
    >> I tried setting the NSUserDefaultsController's custom class attribute
    >> in Interface Builder, but it seems to be ignored, when creating
    >> controllers (Is this a bug in IB? or am I not supposed to be
    >> overriding the behavior of controllers?)
    >>
    >> I also tried setting a delegate for NSUserDefaults, but that doesn't
    >> appear to be supported.
    >>
    >> Any suggestions?
    >
    > What I would do is to bind stuff in the preferences panel to a custom class,
    > and bind the stuff in the custom class to the NSUserDefaults. That way,
    > there is no need for a subclass of NSUserDefaults; the functionality you're
    > looking for would be handled by the intermediate class. Binding "chains" of
    > this sort are quite common in my apps, because I often have three (or more)
    > things to keep in synch. m.

    I should add, though, that if the only problem you're really having is that
    'the "enabled" bindings depend on the value of some of the other settings,'
    that is logic that could easily be handled by a value transform. So then you
    could just go on binding to the vanilla NSUserDefaultsController in the
    normal way. m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today