0

How do I get the temp directory in iOS using Swift? I use this code, but I get the following error:

let localTempURL: URL = try defaultFileManager.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

The operation couldn’t be completed. (Foundation._GenericObjCError error 0.)

I found this post, but it's old non-preferred way. I would like to be able to get the temp directory using FileManager.url(for:in:appropriateFor:create:).

daniel
  • 1,446
  • 3
  • 29
  • 65
  • `FileManager.default.temporaryDirectory` didn't work for you? – TheTiger Sep 27 '18 at 06:17
  • @TheTiger I'm not able to use temporaryDirectory because the iOS version I'm coding for is older. Last time I looked that was for iOS 11 Beta. I'm coding for iOS 10. – daniel Sep 27 '18 at 16:25
  • http://nshipster.com/nstemporarydirectory/ – Cœur Sep 27 '18 at 17:01
  • @ShinehahGnolaum Just checked [From the XCode](https://i.imgur.com/QAFFEtz.png) – TheTiger Sep 28 '18 at 04:45
  • @TheTiger Yes. I checked the documentation. I got confused. I also checked my project settings. I was set to be backward compatible to iOS 8. That is probably unnecessary. – daniel Sep 28 '18 at 09:21

0 Answers0