ObjcBool is not convertible to Bool

In Xcode 8 beta 4 (8S188o),the following code error:


var isFolder:ObjCBool = false;

fileManager.fileExists(atPath: path, isDirectory: &isFolder);

if isFolder { ------> "ObjcBool" is not convertible to "Bool"

fileInfo.isFolder = true;

}


Why is this?

Replies

Did you try with another name : var thisIsFolder : ObjBool = false

This is fallout from the removal of the

Boolean
protocol.

The direct fix is to write this:

var b = ObjCBool(false)

However, a better option is to use a more Swift-friendly API, one that doesn’t rely on the

ObjCBool
. For example, with the new Swift interface to Foundation you can check the type of an item at a URL using code like this:
let u = URL(fileURLWithPath: "/")
if let v = try? u.resourceValues(forKeys: [.isDirectoryKey]) {
    if v.isDirectory! {
        print("directory exists")
    } else {
        print("something else exists")
    }
} else {
    print("does not exist")
}

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

As eskimo noted, the protocol Boolean has been removed from Swift, thus you can use only Bool in conditional expression, no DarwinBoolean nor ObjCBool.


And, in your case "the direct fix" should be something like this:

    if isFolder.boolValue {
        //...
    }

Are you really an eskimo? I'm from Alaska, just wondering

@alaskan907 According to the interview at http://preserve.mactech.com/articles/mactech/Vol.16/16.06/Jun00FactoryFloor/index.html :

“The epithet "The Eskimo!" is from an old Bob Dylan song, since covered by Manfred Mann amongst others.”

“I was born in Kenya and my folks are English. I grew up in Perth, Western Australia, and I'm now living in California.”