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:
NSSearchPathForDirectoriesInDomains
returns an array of pathsFileManager
’surls(for directory: FileManager.SearchPathDirectory, in domainMask: FileManager.SearchPathDomainMask)
returns an array of URLNSHomeDirectory()
returns 1String
String
(ie paths) are missing the URL management methods thatNSString
had
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")
}
// ...
}