file date in apps documents folder

My app creates .pdf files in its documents folder. I need to be able to remove them after one week to keep the users device from filling up with out of date files.


So far, I have discovered that the files can only be removed from the class they were written in. Is there a better way of removing files?

I am considering a func in the creation class that can be called from my cleanup class to remove out of date files. How to I find the creation date for these files?

As a workaround I could store the creation date in CoreData and fetch them with a predicate.

> Is there a better way of removing files?


I assume you have URLs for these files, so couldn't you just use FileManager.removeItem(at:)?


> How to I find the creation date for these files?


Use URL.resourceValues(forKeys:) and pass .creationDate.

file date in apps documents folder
 
 
Q