how to list all pdf files in my iPhone device swift

Viewed 165

I am working on an app where I need to list all the pdf an text files on device and iCloud Drive. I tried various trick but couldn't find solution.

print(FileManager.default.urls(for: .documentDirectory)!)


extension FileManager {
    func urls(for directory: FileManager.SearchPathDirectory, skipsHiddenFiles: Bool = true ) -> [URL]? {
        let documentsURL = urls(for: directory, in: .userDomainMask)[0]
        let fileURLs = try? contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: skipsHiddenFiles ? .skipsHiddenFiles : [] )
        return fileURLs
    }
}

but it is returns nil.

0 Answers
Related