I\'m trying to understand how to use the function fileExistsAtPath:isDirectory: with Swift but I get completely lost.
This is my code example:
Tried to improve the other answer to make it easier to use.
enum Filestatus {
case isFile
case isDir
case isNot
}
extension URL {
var filestatus: Filestatus {
get {
let filestatus: Filestatus
var isDir: ObjCBool = false
if FileManager.default.fileExists(atPath: self.path, isDirectory: &isDir) {
if isDir.boolValue {
// file exists and is a directory
filestatus = .isDir
}
else {
// file exists and is not a directory
filestatus = .isFile
}
}
else {
// file does not exist
filestatus = .isNot
}
return filestatus
}
}
}