A FileManager Swift extension to manage iOS file systems basics with ease
I recently spent some time figuring out the best way to find the URL/paths of the recommended iOS file system used directories.
I felt that iOS URL/paths was very confusing:
NSSearchPathForDirectoriesInDomainsreturns an array of pathsFileManager’surls(for directory: FileManager.SearchPathDirectory, in domainMask: FileManager.SearchPathDomainMask)returns an array of URLNSHomeDirectory()returns 1StringString(ie paths) are missing the URL management methods thatNSStringhad
So I came up with this little FileManager’s extension that could be useful to
many:
extension FileManager {
func homeDirectory() -> URL {
return URL(fileURLWithPath: NSHomeDirectory())
}
func homeDirectoryPath() -> String {
return NSHomeDirectory()
}
func tmpDirectory() -> URL {
return homeDirectory().appendingPathComponent("tmp")
}
// ...
}