• 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: How to get Notification of particular NSUserDefault keys (from the NSGlobalDomain)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get Notification of particular NSUserDefault keys (from the NSGlobalDomain)


  • Subject: Re: How to get Notification of particular NSUserDefault keys (from the NSGlobalDomain)
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 05 Nov 2011 00:47:34 -0500

On Nov 2, 2011, at 1:47 PM, Travis Griggs wrote:

> I'm trying to create a language binding into the Cocoa environment. And my current problem is how to be able to determine when NSUserDefaults values have changed.

> [...] I just want to know when a user changes a value found in the NSGlobalDomain. In particular at the moment, the result I read with the command line expression
>
> defaults read NSGlobalDomain AppleShowScrollBars

You can't.  There's no general means to know when other processes change defaults, especially in domains other than your app's.

However, there's a very good chance that System Preferences sends out a distributed notification when it changes that setting.  The exact name of that notification is an implementation detail which could change at any time and relying on it in a shipping application is inviting trouble.  I don't know for sure that there is such a notification nor what its name might, but you can write a program which monitors _all_ distributed notifications and find out for yourself.  Just watch what happens when you toggle that System Preferences setting.

        NSDistributedNotificationCenter* center = [NSDistributedNotificationCenter defaultCenter];
        [center addObserver:self selector:@selector(observeDistributed:) name:nil object:nil];

- (void)observeDistributed:(NSNotification*)notification
{
    NSLog(@"NSDistributedNotificationCenter: %@\n%@", [notification name], notification);
}

Regards,
Ken

_______________________________________________

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

References: 
 >How to get Notification of particular NSUserDefault keys (from the NSGlobalDomain) (From: Travis Griggs <email@hidden>)

  • Prev by Date: Re: Printing image represented by multiple tiles using Cocoa
  • Next by Date: automaticallyNotifiesObserversOf<property>
  • Previous by thread: How to get Notification of particular NSUserDefault keys (from the NSGlobalDomain)
  • Next by thread: Issue with IOHIDDeviceOpen and Exclusive Access
  • Index(es):
    • Date
    • Thread