Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created March 23, 2015 07:48
Show Gist options
  • Save JadenGeller/1ff15b9958400f18f2c1 to your computer and use it in GitHub Desktop.
Save JadenGeller/1ff15b9958400f18f2c1 to your computer and use it in GitHub Desktop.
Cast Int to Bool in Swift
extension Bool {
init<T : IntegerType>(_ integer: T){
self.init(integer != 0)
}
}
// Now you can do this
let x = Bool(5) // true
let y = Bool(-1) // true
let z = Bool(0) // false
@jimmyrogue
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment