How to add or import multiple items to a file which saved in Documents Directory with Swift?

断了今生、忘了曾经 提交于 2019-12-08 03:49:15

问题


As you can see, here is how to add a word "hello" to a Test.txt (saved in Documents Directory of an app):

let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

let archiveURL = documentsDirectory.appendingPathComponent("Test").appendingPathExtension("txt")

try! Data("hello".utf8).write(to: archiveURL)

Suppose I have a txt or csv file (with 300 names saved one by one in line: Picture1), which is saved in iCloud Drive or somewhere. How can I add those names to the Test.txt file (saved in Documents Directory of an app) with one time, just the following gif shows (Picture 2). Any suggestions would be appreciated.

来源:https://stackoverflow.com/questions/46842890/how-to-add-or-import-multiple-items-to-a-file-which-saved-in-documents-directory

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