如何解决无法在同一文件夹中保存多个文本文件MacOS Swift 应用程序
我正在尝试将多个文本文件保存在同一文件夹中。到目前为止,我可以将一个文本文件保存到我的文档目录中的生成文件夹中,但我不能在同一文件夹中保存多个文本文件。
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)
let documentsDirectory = paths[0]
let docURL = URL(string: documentsDirectory)!
let dataPath = docURL.appendingPathComponent("User_Notes")
if !FileManager.default.fileExists(atPath: dataPath.path) {
do {
try
FileManager.default.createDirectory(atPath: dataPath.path,withIntermediateDirectories: true,attributes: nil)
// try stringToWrite.write(to: &dataPath)
try stringToWrite.write(toFile: "\(dataPath)/\(userNotes)).txt",atomically: true,encoding: String.Encoding.utf8)
} catch {
print(error.localizedDescription)
}
}
if error != nil {
print("Error saving user data.")
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。