问题
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