Archiving my macOS target app fails with BOOL error

I'm building a macOS target for my App (which also has some Obj-C code).

Building and running the app is fine but when I archive the app in XCode, the process / build fails with the following error

Type 'BOOL' (aka ;Int32') cannot be used as a boolean;test for '!=0' instead

It happens in a couple of places, one of the places being

private func getRootDirectory(createIfNotExists: Bool = true) throws -> URL {
        return try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
 }

where it complains that create: true is not acceptable and throws the above error.

If I comment out this line, the archive works successfully.

When i Cmd + click the definition of Filemanager.default.url , i get this

@available(macOS 10.6, *)
    open func url(for directory: FileManager.SearchPathDirectory, in domain: FileManager.SearchPathDomainMask, appropriateFor url: URL?, create shouldCreate: BOOL) throws -> URL

This looks fishy since it it says create shouldCreate: BOOL whereas the documentation says it should be just Bool

func url(
    for directory: FileManager.SearchPathDirectory,
    in domain: FileManager.SearchPathDomainMask,
    appropriateFor url: URL?,
    create shouldCreate: Bool
) throws -> URL

My minimum deployment target is macOS 13.0

I'm quite stumped at this error - which happens only while archiving. Does anybody know why?

Answered by borarak in 789598022

The solution is to use BOOL(1) instead of true (Swift bool)

After fiddling around, the error goes away on upgrading the minimum deployment target to 13.1

Is this a XCode bug?

While this temporarily resolves my issue - I would like to support older macOS versions later and this is still a blocker for that.

So, it worked for a while and then the error just re-appeared on deployment target 13.1 as well. Back to square one.

Accepted Answer

The solution is to use BOOL(1) instead of true (Swift bool)

It’s hard to explain the symptoms you’ve described here. To help isolate it, I’d like you to create a new project from Xcode’s macOS > App template and then put your code in there. Does that exhibit the same problem?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Archiving my macOS target app fails with BOOL error
 
 
Q