4

I've successfully used the following to get the tmp/ directory in iOS:

let path = NSURL.fileURL(withPath: NSTemporaryDirectory(), isDirectory: true)

API docs would seem to prefer we use FileManager to get the Documents/ directory:

let path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first

Is there a way to use FileManager.default.urls(for:in:) or something similar to get the tmp/ directory in iOS? I tried .itemReplacementDirectory and .url(for:in:appropriateFor:create:), but they didn't work.

Any help/guidance would be greatly appreciated!

Swift 3, iOS 10

curieux
  • 713
  • 1
  • 7
  • 15
  • Since the docs for `FileManager.SearchPathDirectory` doesn't show anything related to the "temporary" folder, probably not. – rmaddy Apr 18 '17 at 21:15
  • @rmaddy, Thanks! That's exactly what I was thinking. However, I found the answer (pls see below). – curieux Apr 18 '17 at 21:26

1 Answers1

14

The correct answer is simply:

let tmpURL = FileManager.default.temporaryDirectory

Sometimes, you just need to take a break and come back to it later... =)

curieux
  • 713
  • 1
  • 7
  • 15
  • OK, but that doesn't use the `urls` method which is what your question is asking about. Perhaps your question should ask if `FileManager` can be used instead of specifically asking about `urls`. – rmaddy Apr 18 '17 at 21:36
  • 1
    Naming path a url object it is very misleading, BTW to get its path you would need to get `path.path` – Leo Dabus Apr 18 '17 at 22:02
  • @LeoDabus Thanks for drawing attention to your answer in the duplicate. I couldn't find it on my own, and I tried for quite some time. You're right about the path name, so I edited it. It was an arbitrary name taken from a tutorial, but point taken. – curieux Apr 19 '17 at 02:07
  • @rmaddy That's true, but I did request that "or something similar." I appreciate the time you took to try to resolve my issue, though! – curieux Apr 19 '17 at 02:09
  • 2
    it only supports ios 10 above – iSean May 23 '18 at 06:53