> On 2016 Oct 14, at 23:08, Gerriet M. Denkmann <g...@mdenkmann.de> wrote:
> My app (macOS 12) observes a value in NSUserDefaults. Starting with macOS 12
> observeValueForKeyPath:… is called at the start of the program, although
> nothing has changed yet. When the value actually changes, it is called twice.
I just added some code to one of my apps, to test this. It confirmed your
observations, although I only tested in 10.12.
> Also: NSKeyValueObservingOptionNew or NSKeyValueObservingOptionOld just
> return NSNull instead of old or new values.
That only happens during that first spurious call, when the observer is added.
> Any workaround for these multiple (and unnecessary) calls?
As always when dealing with undocumented behavior, reverse-engineer :))
Regarding that initial call, assuming that NSNull is not a legitimate possible
value, use that NSNull to identify the call as spurious and ignore it.
Regarding the later duplicate calls, ignore if the new value is the same as the
current value. I have seen Cocoa emit such redundant notifications or
observations in other situations, and have had success filtering them in this
You can often get clues about such changes in macOS releases by carefully
searching Apple’s Release Notes for something related, or by filing a
well-written Bug Report – I’ve received short explanations, anonymous, but
obviously written by an engineer on the relevant team. If indeed this behavior
is new in 10.12, it certainly warrants a Bug Report.
Cocoa-dev mailing list (Cocoaemail@example.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:
This email sent to arch...@mail-archive.com