Swift的if语句中的布尔值

时间:2016-07-07 19:55:56

标签: swift

我试图在swift的if语句中写一个布尔值。即使我明确检查它是否为假,它也会出错。

if (bool == false){
  //asks to check for != nil
}

这是原始代码

var schoolName = ""
var NYUClicked : Bool = false
var CooperClicked : Bool = false
var TheNewSchoolClicked : Bool = false
var BaruchClicked : Bool = false
var FITClicked : Bool = false
var SVAClicked : Bool = false

// NYU
@IBOutlet weak var NYUButton: UIButton!

@IBAction func NYUClicked(sender: AnyObject) {
    if ((CooperClicked || TheNewSchoolClicked || BaruchButton || FITClicked || SVAClicked) == false)

1 个答案:

答案 0 :(得分:3)

BaruchButton不是Bool。你想要BaruchClicked

直接针对truefalse进行检查并不常见。与false的比较最好通过简单的否定来完成:

if !(CooperClicked || TheNewSchoolClicked || BaruchClicked || FITClicked || SVAClicked) {
}