i’d like to save some “workspace” type settings: settings that are tied to the document rather than to the app itself.

things like the selected tab, the sidebar widths, etc.these need to persist even if the user doesn’t save the document — so they’re definitely settings, not document data.

anyone else doing this?

i was hoping there was some hidden corner of NSUserDefaults that handled this, but that doesn’t seem to be the case.

@isaiah For SwiftUI, SceneStorage is like AppStorage only per window. I don’t know how to map this to UserDefaults but there must be a link.

@troz per window isn’t really sufficient — unless the document is mapped to a specific window.

what i want is basically Xcode. if i open a project, i want the the same files open, the same left sidebar tab should be selected, as the last time i viewed that project.

this is neither a user defaults sort of thing (which is global, nor the settings of a particular UI element) nor is it part of the NSDocument model. it’s the stuff in the xcuserdata of each xcode project.

@isaiah @troz I suspect that Xcode does not use NSDocument, I think it predates that API. It probably has a bespoke implementation all its own. I don’t think you can duplicate that behavior with NSDocument. In Panorama, I just save that information as part of the document. If you want it to automatically save even if nothing else changes, it has to be hooked into the undo say. I didn’t do that, so metadata changes aren’t saved unless something else is changed, or if the user explicitly saves. Never had a single complaint about this behavior.