How to delete a folder in Swift

In this code you can how we can delete folder in Swift. You have to specify the path of the directory which you want to delete and call the removeItem() 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 folder = playgroundURL.appendingPathComponent(“test-directory-new”).path

try fileManager.removeItem(atPath : folder)
} catch {