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 I've been doing that for years now. Just a dictionary of key values stored in a plist file within the document bundle. I just load it in when the document is instantiated. I modeled it directly after NSUserDefaults. I called it ..... TFUserDefaults. Very original 😆

@tapforms if you do save it to the project bundle, even when the NSDocument model hasn’t changed, can i ask how you decide when to write that file?

i can do it, but it seems like there’s a a potential race condition. when the user chooses save the project bundle will be replaced atomically i think — thus nuking any extra files in the bundle.

@isaiah I save whenever I call defaults.setXxxFor(key:). Just a plist write to the file system within the document bundle folder. DocumentProperties.plist is the file I wrote to. And since my app is a database app I write to the database all the time as users make changes. Not just by pressing save. My document is never really in a dirty state.