Le 15 août 2009 à 21:18, Sandro Noel a écrit :

Greetings.

I would like to watch to prefeences change in my application.
so i add these observers as so:

settings = [NSUserDefaultsController sharedUserDefaultsController];
[settings addObserver:self
forKeyPath:@"values.filesPath"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:NULL];

My observers are registered in applicationDidFinishLaunching.

I do successfully receive the notification for my key path.
but the change directory only returns null values for the old and the new values, I do not know what i'm doing wrong.



if i fetch the new value directly from the UserDefaultsController the path did change and I can use it from there.
but I would need the old value to remove the old path from my monitor.

[...]

Any clues would be great !!!
thank you !
        


Don't know why it behaves like this, but you can probably work around this by using the NSKeyValueObservingOptionPrior option. By setting this option, you will receive a notification before the new value is set, and you can retrieve the old value. In your observer, you can detect if the notification is the prior one by querying the NSKeyValueChangeNotificationIsPriorKey key in the change dictionary.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to