In Swift, when you see a symbol with a leading dot (in this case .documentDirectory, it means that whatever is infront of the dot is inferred by compiler, usually itās the type that is expected from that location.
Youāre trying to call fileManager.urls(for: .documentDirectory, in: .userDomainMask) which has 1 overload:
fileManager.urls(for directory: FileManager.SearchPathDirectory, in domainMask: FileManager.SearchDomainMask) -> [URL]
So the compiler infers what you write into
fileManager.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchDomainMask.userDomainMask) -> [URL]
FileManager separate URLs into domain, for example, systemDomain(/), userDomain(~/), each domain may contain a common directory specify by SearchPathDirectory, such as downloadDirectory (./Downloads).
Your code is trying to access a download folder in user domain. In macOS, it would resolve into ~/Downloads, but I suspect that thereās no such folder in iOS file system.
Though I donāt know whatās wrong with the code (since I canāt test it and you simply say that it doesnāt work), thatād be my guess.
Do note that the actual base path may be different due to other factors such as sandboxing, etc.
Note: your code is trying to list a content in documentURL, not dir, youāll need to convert dir to URL, then use it instead of documentURL