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

504 views Asked by At

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)

Picture1

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.

Picture 2

0

There are 0 answers