archiverootobject和unarchiverootobject的有效文件路径 [英] Valid file path for archiverootobject and unarchiverootobject

查看:183
本文介绍了archiverootobject和unarchiverootobject的有效文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作iPhone应用程序并在之前的问题中被告知我需要archiverootobject和unarchiverootobject的有效文件路径,但我不知道如何制作一个。那么保存自定义类数组的有效文件路径是什么?

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?

推荐答案

您可以将它保存到应用程序支持文件夹中以您的bundleID命名的子目录文件夹中也可以将它保存到库目录中的首选项文件夹中:

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

这篇关于archiverootobject和unarchiverootobject的有效文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆