How to get contents of directory

October 15, 2017

In iOS programming you have to list the contents of the folder. I am using contentsOfDirectory() method of the FileManager class

let home = FileManager.default.homeDirectoryForCurrentUser
let playgroundPath = "Documents/dev/xcode/DatePicker/c"

// Get your playground URL
let playgroundURL = home.appendingPathComponent(playgroundPath)

// First create a FileManager instance
let fileManager = FileManager.default

let path = playgroundURL.path

   let  files = try fileManager.contentsOfDirectory(atPath: path)
} catch   {