NSUserDefaults and binding to an NSDictionary

  • Hi there,

    I have a simple question regarding bindings and user defaults and I
    could not find an answer in any of the mailing lists (it is probably
    very obvious).

    My user defaults contain a few booleans, strings and numbers all of
    which work fine when bound to various text fields and checkboxes.

    So, my question is: how do I bind values that are included in an
    NSDictionary which itself is one of my user defaults?

    Here is the typical structure of my user defaults:

    --> Key: @"Preference 1", Value (NSString): @"any string"
    --> Key: @"Preference 2", Value (NSNumber): 1234
    --> Key: @"Sub Preferences", Value (NSDictionary):
      --> Key: @"Sub Preference 1", Value (NSString): @"any string"
      --> Key: @"Sub Preference 2", Value (NSNumber): 4567

    So, I tried binding a text field to "Sub Preferences.Sub Preference
    1" but all it does is create a "Sub Preferences.Sub Preference 1"
    string and not a dictionary containing the string.

    Has anybody done that already?

    Thanks!

    Daniel Tapie,
    Brussels, Belgium
  • On Mon, 16 Oct 2006 14:23:24 +0200, Daniel Tapie <dtapie...>
    said:
    > Hi there,
    >
    > I have a simple question regarding bindings and user defaults and I
    > could not find an answer in any of the mailing lists (it is probably
    > very obvious).
    >
    > My user defaults contain a few booleans, strings and numbers all of
    > which work fine when bound to various text fields and checkboxes.
    >
    > So, my question is: how do I bind values that are included in an
    > NSDictionary which itself is one of my user defaults?
    >
    > Here is the typical structure of my user defaults:
    >
    > -->  Key: @"Preference 1", Value (NSString): @"any string"
    > -->  Key: @"Preference 2", Value (NSNumber): 1234
    > -->  Key: @"Sub Preferences", Value (NSDictionary):
    > --> Key: @"Sub Preference 1", Value (NSString): @"any string"
    > --> Key: @"Sub Preference 2", Value (NSNumber): 4567
    >
    >
    > So, I tried binding a text field to "Sub Preferences.Sub Preference
    > 1" but all it does is create a "Sub Preferences.Sub Preference 1"
    > string and not a dictionary containing the string.

    Aside from the question of how you are naming your keys, the big trick here
    is to pass thru a controller where Handles Content as Compound Value is
    checked. 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>
  • Hi Matt,

    Are you implying I cannot use the Shared Defaults Controller in this
    case?

    Thanks for your reply!

    On 16 oct. 06, at 21:02, Matt Neuburg wrote:

    > On Mon, 16 Oct 2006 14:23:24 +0200, Daniel Tapie
    > <dtapie...>
    > said:
    >> Hi there,
    >>
    >> I have a simple question regarding bindings and user defaults and I
    >> could not find an answer in any of the mailing lists (it is probably
    >> very obvious).
    >>
    >> My user defaults contain a few booleans, strings and numbers all of
    >> which work fine when bound to various text fields and checkboxes.
    >>
    >> So, my question is: how do I bind values that are included in an
    >> NSDictionary which itself is one of my user defaults?
    >>
    >> Here is the typical structure of my user defaults:
    >>
    >> --> Key: @"Preference 1", Value (NSString): @"any string"
    >> --> Key: @"Preference 2", Value (NSNumber): 1234
    >> --> Key: @"Sub Preferences", Value (NSDictionary):
    >> --> Key: @"Sub Preference 1", Value (NSString): @"any string"
    >> --> Key: @"Sub Preference 2", Value (NSNumber): 4567
    >>
    >>
    >> So, I tried binding a text field to "Sub Preferences.Sub Preference
    >> 1" but all it does is create a "Sub Preferences.Sub Preference 1"
    >> string and not a dictionary containing the string.
    >
    > Aside from the question of how you are naming your keys, the big
    > trick here
    > is to pass thru a controller where Handles Content as Compound
    > Value is
    > checked. 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>
    >
    >
    >
    >

    Daniel Tapie
  • On or about 10/16/06 12:15 PM, thus spake "Daniel Tapie"
    <dtapie...>:

    > Hi Matt,
    >
    > Are you implying I cannot use the Shared Defaults Controller in this
    > case?

    No. m.

    > On 16 oct. 06, at 21:02, Matt Neuburg wrote:
    >
    >> On Mon, 16 Oct 2006 14:23:24 +0200, Daniel Tapie
    >> <dtapie...>
    >> said:
    >>> Hi there,
    >>>
    >>> I have a simple question regarding bindings and user defaults and I
    >>> could not find an answer in any of the mailing lists (it is probably
    >>> very obvious).
    >>>
    >>> My user defaults contain a few booleans, strings and numbers all of
    >>> which work fine when bound to various text fields and checkboxes.
    >>>
    >>> So, my question is: how do I bind values that are included in an
    >>> NSDictionary which itself is one of my user defaults?
    >>>
    >>> Here is the typical structure of my user defaults:
    >>>
    >>> --> Key: @"Preference 1", Value (NSString): @"any string"
    >>> --> Key: @"Preference 2", Value (NSNumber): 1234
    >>> --> Key: @"Sub Preferences", Value (NSDictionary):
    >>> --> Key: @"Sub Preference 1", Value (NSString): @"any string"
    >>> --> Key: @"Sub Preference 2", Value (NSNumber): 4567
    >>>
    >>>
    >>> So, I tried binding a text field to "Sub Preferences.Sub Preference
    >>> 1" but all it does is create a "Sub Preferences.Sub Preference 1"
    >>> string and not a dictionary containing the string.
    >>
    >> Aside from the question of how you are naming your keys, the big
    >> trick here
    >> is to pass thru a controller where Handles Content as Compound
    >> Value is
    >> checked. 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>
    >>
    >>
    >>
    >>
    >
    >
    >
    > Daniel Tapie
    >

    --
    matt neuburg, phd = <matt...>, http://www.tidbits.com/matt/
    pantes anthropoi tou eidenai oregontai phusei
    AppleScript: the Definitive Guide - Second Edition!
    http://www.amazon.com/gp/product/0596102119
    Take Control of Word 2004, Tiger, and more -
    http://www.takecontrolbooks.com/tiger-customizing.html
    Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
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