NSUserDefaults are reset to defaults when opening an NSOpenPanel or NSSavePanel on macOS High Sierra

Originator:lextar
Number:rdar://34759647 Date Originated:October 1 2017, 3:11 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:macOS 10.13 (17A365)
Classification:Serious Bug Reproducible:Sometimes
 
Area:
AppKit

Summary:
In my Mac app Textastic, a text editor, I store the preferences in NSUserDefaults and bind UI controls to NSUserDefaultsController to get notified when the preferences change.

This used to work without problems, but on High Sierra I see this problem:

Sometimes when I open an NSOpenPanel or NSavePanel, I get notifications from NSUserDefaultsController and all settings are reset to the defaults I registered with -[[NSUserDefaults standardUserDefaults] registerDefaults:] and 
[[NSUserDefaultsController sharedUserDefaultsController] setInitialValues:].

This means that all settings are reverted to their initial values. But, when I restart the app, it uses the correct values again. 

So it seems that calling open or save panels makes the app lose access to the preferences and thus it uses the default values instead.

This is a major problem in my app.

Steps to Reproduce:
- open Textastic, set the editor theme and font size to something different than the default
- quit and restart the app
- hit Cmd-O to open an open panel (or close an untitled file which shows a save panel)

Expected Results:
- the user-selected theme and font size should stay

Actual Results:
- the theme and font size are reverted to their default values. NSUserDefaultsController fires notifications for the values stored in NSUserDefaults, so the theme and font size of the text editor is change to the default values.


Version/Build:
macOS 10.13 (17A365)

Configuration:
MacBookPro10,1


I have added a sysdiagnose to this bug report that I created right after the problem occured. 
The problem happened at about this time: So  1 Oct 2017 15:06:58 CEST
The PID of my app was 60030


Unfortunately I cannot reproduce this bug reliably. It only happens sometimes and it seems to happen more often if I wait a few minutes before opening the app and opening the open or save panel.

Maybe this happens because the open panel is a remote view and my app is sandboxed?

Was something changed regarding KVO in High Sierra? I don't know how to debug this, but the same app worked without problems in macOS Sierra. I have looked through my code and cannot find anything unusual in how I use NSUserDefaultsController, so I think this is a bug in High Sierra.

I would welcome any insights as to what might cause this issue. Maybe there is something I can fix in my app.

Comments

Video

I've uploaded the video that shows the problem in TextEdit:

https://www.youtube.com/watch?v=udGSHUMOpxE

October 9 2017, 4:16 PM

I can reproduce the problem in TextEdit on macOS 10.13 (17A405):

  1. Open TextEdit
  2. Open the Preferences screen
  3. Set the "Format" setting to "Plain Text" (standard is "Rich Text")
  4. Quit TextEdit and wait a few seconds
  5. Launch TextEdit
  6. Use File -> Open… or Cmd-O to show the open dialog

Expected Results: The preferences should not change.

Actual Results: The "Format" preference changes from "Plain Text" to "Rich Text".

If you quit and re-launch TextEdit, the preferences screen shows "Plain Text" again.

I have attached a video showing the problem!


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!