How to create folder in Swift

October 15, 2017

To create a folder in iOS app development, you can use the createDirectory() 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.appendingPathComponent("test-directory").path


do{
    try fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
} catch   {
    print("error")
}