0

I followed the code exactly in the link: Read and write data from text file (Swift 2.2 solution) I am writing the same code in playground file I created.

let file = "file.txt"
let text = "some text"

if let dir = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.AllDomainsMask, true).first {
let path = NSURL(fileURLWithPath: dir).URLByAppendingPathComponent(file)

//writing
do {
    try text.writeToURL(path, atomically: false, encoding: NSUTF8StringEncoding)
}
catch {/* error handling here */}
}

There are no error messages. The code runs fine. But I am not able to find the file - file.txt using my Mac finder.

How do I locate the file in the system?

Community
  • 1
  • 1
Suhas
  • 101
  • 9
  • Open Terminal and enter "find . -name file.txt". Not a question about programming as such though. – kometen Nov 15 '16 at 20:55
  • I tried to find using terminal, but i get the following error: find . -name mySavedFile.csv ./Library/Developer/XCPGDevices/6F0E15A6-01DC-4AE8-80A3-E147FEF9D581/data/Containers/Data/Application/C06AD9E4-157F-4FAB-8149-66FCB27E692B/tmp/mySavedFile.csv find: ./Library/Saved Application State/com.adobe.flashplayer.installmanager.savedState: Permission denied – Suhas Nov 15 '16 at 21:06
  • Thanks a lot.. Got. I am new to using a Mac system. The Finder was not able to find the file, but the terminal did find it. – Suhas Nov 15 '16 at 21:17

1 Answers1

0

In the Playground editor, on the right side it should give you a text representation of the URL. You can right click and choose "Open URL". This will open the text file and you can examine the title bar of TextEdit (right-click title) to find the exact path and move to point therein.

Mundi
  • 79,884
  • 17
  • 117
  • 140