I downloaded some PDF files in my app and want to delete these on closing the application.
For some reason it does not work:
Creating the file:
l
I believe your problem is on this line:
let filePaths = try fileManager.contentsOfDirectoryAtPath("\(documentsUrl)")
You're using contentsOfDirectoryAtPath()
with something that is an NSURL
. You choose either path strings or URLs, not try to mix them both. To pre-empty your possible next question, URLs are preferred. Try using contentsOfDirectoryAtURL()
and removeItemAtURL()
.
Another curious thing you should look at once you resolve the above: why are you using NSTemporaryDirectory()
for the file path when you try to delete? You're reading the document directory and should use that.