How to access the device's downloaded directory, not the app specific one

Hello, I was wondering how to list files ( videos, images ) that the user has downloaded OUTSIDE the app via safari etc. .

I tried something like below, but did not work causing error : The file “Downloads” couldn’t be opened because there is no such file.

 let fileManager = FileManager.default
 let documentsURL = fileManager.urls(for: .downloadsDirectory, in: .userDomainMask)[0]

The file “Downloads” couldn’t be opened because there is no such file.

It gave you the correct URL. Either the directory didn’t exist (yet) when you tried to access it, or you don’t have permission to read from there. Is there a sandbox in the way?

well I think they gave me the url /Users/namios/Library/Developer/CoreSimulator/Devices/459E446B-B15A-41B2-A66D-83E50E3104A0/data/Containers/Data/Application/FFDF41EE-7A78-4581-83D8-3783D477435A/Downloads and this url seems like a directory created just for this specific app. I wish i could access the one where the user downloads file without this app, like when they just surf the web with safari and chooses to download an image.

It has created a downloads directory for you in your sandbox, because you haven’t gotten permission to access the system one. Sandboxes are more related to the platform than to Swift. You can read about them here, and ask questions about them over at the Apple Developer Forums.


Oh, I guess i kinda misunderstood the purpose of this community. Thanks for the guidance