No, there is and has never been an explicit built in option for conversion of Int to Bool, see the language reference for Bool for details.
There exists, still, however, an initializer by NSNumber. The difference is that implicit bridging between Swift numeric type and NSNumber has been removed in Swift 3 (which previously allowed what seemed to be explicit Bool by Int initialization). You could still access this by NSNumber initializer by explicitly performing the conversion from Int to NSNumber:
let number = 1
let result = Bool(number as NSNumber)
print(result) // true
As @Hamish writes in his comment below: if we leave the subject of initializers and just focus on the end result (instantiating a Bool instance given the value of an Int instance) we can simply make use of the != operator for Int values (specifically, the operator with signature func !=(lhs: Int, rhs: Int) -> Bool), a generalization easily achievable using the != operator approach:
let number = -1
let result = number != 0
print(result) // true
Much like you yourself as well as @JAL describes in his answer, you could construct your own Bool by Int initializer, but you might as well consider generalizing this for any type conforming to the Integer protocol:
extension Bool {
init<T: Integer>(_ num: T) {
self.init(num != 0)
}
}
/* example usage */
let num1: Int8 = -1
let num2: Int = 3
let num3: UInt64 = 0
// ....
let result1 = Bool(num1) // true
let result2 = Bool(num2) // true
let result3 = Bool(num3) // false
true, and0asfalse, but that's just a consequence of the implementation details of encoding true vs false in memory. When you think about it, it actually makes little sense, semantically. So instead, just use explicitlyi != 0, to be clear about precisely what you mean. Over-assuming its generalizability and naming it something likeboolValueis ambiguous. For one, Bash/linux exit codes are the opposite. 0 is good/true, non-zero is bad/false. - Alexander