To create a directory in Swift, you can make use of the FileManager
class. Here's how to do it:
main.swift782 chars20 lines
In the example code above, we:
documentDirectory
URL of the app using the FileManager
.FileManager
class's createDirectory()
method.withIntermediateDirectories
parameter allows intermediate directories to be created if they don't already exist. If set to false
and any intermediate directories don't exist, createDirectory()
will fail. The attributes
parameter allows you to set any additional file attributes when creating the directory. In our example, we pass nil
for it.gistlibby LogSnag