The method fileExistsAtPath() in the example below accept single argument only.
if fm.fileExistsAtPath(result, isDirectory:&isDir) {
The exact error message is: "Extra argument 'isDirectory' in call".
Any idea what's wrong?
The problem is that isDirectory
is UnsafeMutablePointer<ObjCBool>
and not UnsafeMutablePointer<Bool>
you provide. You can use the following code:
var isDir = ObjCBool(false)
if NSFileManager.defaultManager().fileExistsAtPath("", isDirectory: &isDir) {
}
if isDir.boolValue {
}
Some might find this a little neater. This is Swift 3.
var directory: ObjCBool = ObjCBool(false)
var exists: Bool = FileManager.default.fileExists(atPath: "…", isDirectory: &directory)
if exists && directory.boolValue {
// Exists. Directory.
} else if exists {
// Exists.
}
It is
func isDirectory(path: String) -> Bool {
var isDirectory: ObjCBool = false
NSFileManager().fileExistsAtPath(path, isDirectory: &isDirectory)
return Bool(isDirectory)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With