You can delete a directory using the FileManager class in Swift. The following code shows how to delete a directory with its contents:
main.swift215 chars9 lines
In this code, we first create an instance of the FileManager
class. Then, we create a URL
object for the directory we want to delete.
Next, we use a do-catch
block to call the removeItem(at:)
method on the fileManager
object, passing in the directoryURL
object. This removes the directory and all its contents.
If an error occurs while deleting the directory, the catch block prints an error message.
gistlibby LogSnag