Reputation: 49
I am using Alamofire for download data from the server. I wanted to save in directory whichever is the safest place(DocumentDirectory, NSTemporaryDirectory). Could anyone help me in this?
DocumentDirectory:
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent(fileName)
return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
}
NSTemporaryDirectory
let fileURL = URL(fileURLWithPath:
NSTemporaryDirectory()).appendingPathComponent(fileName)
let destination: DownloadRequest.DownloadFileDestination = { _, _ in
return (fileURL, [.createIntermediateDirectories,
.removePreviousFile])
}
Upvotes: 2
Views: 3409
Reputation: 5164
NSTemporaryDirectory
will be wipe out data once your iOS device is running out of memory. So you can store temporary data on NSTemporaryDirectory
like caching images and other stuff.
NSDocumentDirectory
is useful to store data for long time.
So as per your need you need to use these directories to store data.
For more info please check is saving in NSDocumentDirectory okay?
Upvotes: 5