布尔类型
指逻辑上的,只能是真或者假。用Bool表示。
有两个布尔常量:true和false。
主要用于条件判断语句中,
如在需要使用Bool类型的地方使用了非布尔值,swift的类型安全机制会报错。
var boolvalue1 = true
var boolvalue2 = false
var isFinished = true //type bool
if isFinished {
print("Finished!")
} else {
print("not finished!")
}
var isexist:Bool = false
//isexist = 1 //cannot assign value of type Int to type Bool
//isexist = 3.14159 //cannot assign value of type Double to type Bool
转载于:https://blog.51cto.com/juniqian/1837910