What location do OSX/Cocoa applications generally use to store data files?

点点圈 提交于 2019-12-04 19:27:37

问题


Do they write/store them within the app bundle/package itself? Or some other canonical location? Or does there not seem to be any standard?


回答1:


Files usually go in ~/Library/Application Support/Your App/. Preferences go in ~/Library/Preferences/.




回答2:


NEVER modify a file inside your own app bundle.




回答3:


You should decidedly not write files into your app bundle at runtime. There's no guarantee that a user running your app will have permission to modify it. As Chris said, support files go in Application Support and preferences go in ~/Library/Preferences. To find the user's Application Support folder, you can use the NSSearchPathForDirectoriesInDomains() function. To write preference files, you can use the NSUserDefaults or CFPreferences APIs.



来源:https://stackoverflow.com/questions/2016596/what-location-do-osx-cocoa-applications-generally-use-to-store-data-files

标签

工具导航Map