Valid file path for archiverootobject and unarchiverootobject

℡╲_俬逩灬. 提交于 2019-12-17 07:56:08

问题


I am making an iPhone app and in a previous question I was told that I needed a valid file path for archiverootobject and unarchiverootobject but I don't know how to make one. So what is a valid file path to save arrays of custom classes?

Follow up question: On the linked question I have set up my methods to use invalid saves but it still works would anyone know why?


回答1:


You can save it to a subdirectory folder named with your bundleID inside the application support folder or you can also save it to the preferences folder located inside the library directory:

let preferencesDirectoryURL = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first!.appendingPathComponent("Preferences", isDirectory: true)
let fileURL = preferencesDirectoryURL.appendingPathComponent("fileName.plist")
print(fileURL.path)   // "/var/folders/.../Library/Preferences/fileName.plist


来源:https://stackoverflow.com/questions/34701630/valid-file-path-for-archiverootobject-and-unarchiverootobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!