where to save... file resources?

I'm trying to find the appropriate place to save Application data, not document data, that is not preference data, in the Sandbox aware world we now live in.


I was happy with a resourcefolder I generated, and accessing it's path by getting the resource folder path and just appending the path component, but that directory is nearly impossible to create on the fly (and that's a requirement.)


so I'm rethinking what the data is and where it should be.


basically, the files are document files on the backend. But they are reusable bits of documents that should be loaded at launch, and live in a "shelf," available to the user to mix into his/her document.


so it's Not a preference, there's going to be folders and many many files. And it's not necessarily a resource, so : Application Support? where in the docs can I find that?

Replies

Application Support sounds like the right place, and the legacy documentation on this is still here, for now:


https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html


Note that when non-sandboxed, your app MUST use a subdirectory, to avoid colliding with other apps. This isn't strictly necessary for sandboxed apps, but it's probably a good idea to follow the subdirectory rule anyway.

Hi Quincey,

I was hoping there was some sort of system level object to work with, or some kind of suite of methods in Bundle or FileManager.


but I was able to cobble something together that I think avoids most "hard coding" traps... But I am now mystified by something.

first let's go over what I wound up with:


let newPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Application Support").appendingPathComponent("com." + Bundle.main.bundleIdentifier!).appendingPathComponent("shelf")

I'll unpack that.

so I ask the FileManager for the current user's home directory,

then I append to that : "Application Support",

then I append to that : "com." + the Bundle's identifier. // if I don't add the com, for some reason it's just not included. maybe a malformed bundleID, maybe Apple changed the way they form it. IDK for certain,

then I append : "shelf" // shelf for my app's shelf system.


this gives me something like:

newPath URL "file:///Users/eblu/Application%20Support/com.bkTools.manipDsgnr/shelf/section" // this was copied directly from the debugger. I am making a new section here, and that's why "section" is at the end there.


anyway. here's the problem.

there's no sandboxing, we are in debug mode, but I can't find the files I am creating. There's a container entry for the app (~/Library/containers) but there's NO Application Support folder for the app. And here's the eerie part of the whole thing: the files exist Somewhere. I had a completely fleshed out system before I needed to move to Application support, and when i did that, I just applied the URL change to the whole system... so I'm loading information from SOMEWHERE, I just don't know where.


I've looked through the ~Library/Developer folder structure, and in the App's Package Contents... nothing.

any ideas?

found it. operator error.

easy, in hind sight.