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 @isaiah I think SceneStorage would roughly map to the AppKit state restoration stuff.

@bwebster @troz i thought state restoration was just to get the app back to where it was when it was last running. that’s not quite what i’m after.

i can open an Xcode project. select a specific item. then close the project.

when i come back to that project a year later (even if i’ve viewed 100 projects in between. and xcode will open my old project just as it was when i last looked at it.

it’s not app state. it’s not project file data.

it’s project/workspace state.

@isaiah @troz That’s correct, so scene storage/state restoration definitely wouldn’t fit the bill. I don’t think the frameworks have any built in solution for per document state, so it’s a roll-your-own world.

I have seen a couple apps store stuff in xattrs if it’s small. Might not survive copying to certain drive formats, but otherwise pretty easy out-of-band storage.