0

I wrote a file in .documentDirectory in .userDomainMask:

do {
  let fileManager = FileManager.default
  let docs = try fileManager.url(for: .documentDirectory,
                                 in: .userDomainMask,
                                 appropriateFor: nil, create: false)
  let path = docs.appendingPathComponent("myName.txt")
  let data = "Hai...!".data(using: .utf8)!
  fileManager.createFile(atPath: path.absoluteString, contents: data, attributes: nil)
} catch {
  // handle error
}

I have not gotten any errors or exceptions. It runs perfectly. But I can't see that file. Where can I find that file?

TylerP
  • 9,600
  • 4
  • 39
  • 43
Priya Kavi
  • 57
  • 6
  • What do you mean by see it? It's in your app's sandbox, so you can only view it through Xcode (I believe at least: in devices, view the app's container), or by opening the file in your code and performing some action on it. – Chris Loonam May 06 '20 at 06:08

1 Answers1

0

just add in target -> info -> custom iOS Target properties

Application supports iTunes file sharing - YES and you will be able to see the folder you saved a file in Files app on your simulator.

Otherwise use print(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)) to get a path to folder using Finder

Golgi
  • 20
  • 6