macoscocoacore-datanspersistentdocument

Correct directory for NSPersistentDocument OSX


I am writing a shoebox type application wherein a user enters data into a single window. I’ve configured the data model with Code Data. Apple’s documentation states that user data should be stored in a Library Directory, however the auto-generated code seems to make a directory in the Application Support directory where one, the documentation also states, “should never store user data.” Which is correct? The other question I have is should I not create an instance of NSPersistentDocument in the applicationDidFinishLaunching method?


Solution

  • User-created data should be managed by the user: the user should decide where they are saved, etc.

    Application-created data would indeed belong in the application support directory. If your application creates an NSPersistentDocument without user intervention, this would be the correct place to store it. For example, if you were using NSPersistentDocument to manage application data it would belong in a sandboxed directory such as NSApplicationSupportDirectory.

    The File System Programming Guide goes into this in more detail.