NSUserDefaultsDidChangeNotification with NSUserDefaultsController

  • Hi,

    I'm trying to understand exactly when NSUserDefaultsDidChangeNotification
    is posted.  Or, more generally, when using NSUserDefaultsController, when
    and how can I act on the changed preferences?

    mmalc's "ControlledPreferences" example has been very useful, but I
    notice what I consider a strange behaviour:

    - if I change the textfield, NSUserDefaultsDidChangeNotification is
    posted once
    - the 1st time I click the colourwell (without changing colours), its
    posted 4 times
    - subsequent times, its not posted at all unless i change colours
    - same thing with the 'fonts' button
    - clicking the 'factory' button also gets me 4 postings

    4 is the number of keys this app has in its defaults database.

    In my app, the same happens.  But in response to the changed prefs, I
    need to do a lengthy operation, and so doing it 4 times is bad. :)

    I may turn off the 'appliesImmediately' flag, but I'd still like to
    understand when things are posted.  Apple's docs say only "This
    notification is posted the first time after a synchronize when a change
    is made to defaults in a persistent domain" which doesn't mean much to me.

    Thanks!
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • OK, so I'm replying to my own post here :), for the benefit of the
    archives I guess.

    But I have a new question based on my new findings, but I'll start a new
    thread.

    Sean McBride (<cwatson...>) on Tue, Aug 3, 2004 01:00 said:

    > I'm trying to understand exactly when NSUserDefaultsDidChangeNotification
    > is posted.  Or, more generally, when using NSUserDefaultsController, when
    > and how can I act on the changed preferences?
    >
    > mmalc's "ControlledPreferences" example has been very useful, but I
    > notice what I consider a strange behaviour:
    >
    > - if I change the textfield, NSUserDefaultsDidChangeNotification is
    > posted once
    > - the 1st time I click the colourwell (without changing colours), its
    > posted 4 times
    > - subsequent times, its not posted at all unless i change colours
    > - same thing with the 'fonts' button
    > - clicking the 'factory' button also gets me 4 postings
    >
    > 4 is the number of keys this app has in its defaults database.

    What I did not realise is that the NSUserDefaultsDidChangeNotification
    has changes for bazillions of defaults, not just those related to my app.
    I printed out all the defaults (using [[note object]
    dictionaryRepresentation]) and did a text diff and now understand why I
    see so many notifications: they are not from changes to my defaults at
    all, but the OS's:

    193 : <CFString 0x383fa0 [0x2b9a30e0]>{contents = "NSWindow Frame
    NSColorPanel"} = <CFString 0x383fd0 [0x2b9a30e0]>{contents =
    "325 263 201 309 0 0 1024 746 "}

    143 : <CFString 0xa2dcc530 [0x2b9a30e0]>{contents = "NSColorPanelMode"}
    = <CFString 0x3ca750 [0x2b9a30e0]>{contents = "6"}

    I guess its remembering where the colour panel goes, etc.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month august 2004 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
MindNode
MindNode offered a free license !