0

I am adding an option in my App to backup everything to a file.

For that, I am serializing all my objects to a dictionary that I save in a single file in the path provided by FileManager.default.temporaryDirectory. Then I ask the user for a path to save this file using a UIDocumentPickerViewController.

Everything works fine, but I wonder what happens with the temporal file that I created in the temporaryDirectory. Is this automatically removed by the operating system? should I take care of removing it by myself?

This is how I get the path of the temporary directory for my file:

private var exportURL: URL {
    let documentURL = FileManager.default.temporaryDirectory
    let fileName = "archive"
    let filePath = "\(fileName).backup"
    return documentURL.appendingPathComponent(filePath)
}
StuckOverFlow
  • 851
  • 6
  • 15
  • 1
    You should always cleanup unneeded files when done. But files in the temp directory will eventually be deleted by iOS. It could be when the storage space is getting full or it could be when the app is terminated. It's not documented so can't know for sure when. – HangarRash Jan 07 '23 at 15:35

0 Answers0