I would like to open a .txt file and save the content as a String. I tried this:
let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("xxx.txt")
var contentString = try String(contentsOfFile: path.absoluteString)
print(path)
The print result:
file:///Users/Username/Documents/xxx.txt
But I get the error:
The file “xxx.txt” couldn’t be opened because there is no such file
The file is 100% available
Notice: I working with swift 4 for macOS