In Swift fileExistsAtPath(_ path: String, isDirectory isDirectory: UnsafeMutablePointer<ObjCBool>) -> Bool accepts single parameter only

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.
}

Tags:

Ios

Swift