无法在同一文件夹中保存多个文本文件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 (将#修改为@)