上QQ阅读APP看书,第一时间看更新
Booleans
In Swift, Booleans are capitalized:
let myBool: Bool = true
It will not surprise you to learn that Boolean values come in two flavors: true and false.
However, that really is all you get; true doesn't equal 1, and false doesn't mean nil, or 0, or anything else but false:
let myBool = false
myBool == nil // no it doesn't
myBool == 0 // error
The second line evaluates to false, because myBool does have a value and so will not be equivalent to nil (whether its value is true or false). You'll see shortly that Swift is very choosy about how it handles the concept of nil (see the Optionals section of this chapter).
The third line will not even compile--you'll get an error informing you that you can't compare a Bool with an Int. In Swift, you can have 0 teeth, but you can't have false teeth.