0

I build an iOS App with Swift 4 and would like to import text files (CSV) from the iOS Files app (since iOS 11) into my app. Next step would be to parse the text into an a json, dictionary or array. It depends on the content. I just need read rights.

Does someone has an idea how to do it? I haven’t found any tutorial yet.

UPDATE: My question is, how to get and use an “open file dialog” to select a text file. I removed read from the title.

1024jp
  • 2,058
  • 1
  • 16
  • 25
Moe
  • 43
  • 5

1 Answers1

-2

If you want to get a txt file from a web server, try this:

func download () {

    if let url = URL(string: "http://example.com/file.txt") {
        do {
            let contents = try String(contentsOf: url)
            print(contents)
            let contentarr = contents.components(separatedBy: ";")
            print(contentarr)
        } catch {
            print("Some error happened")
        }
    } else {

print("Wrong URL")

}
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Harcker
  • 151
  • 1
  • 13
  • @Harcker Thanks for your comment, but I look for a solution to show a file dialog to open a text file and be able to read the file. – Moe Feb 18 '18 at 17:03