我试图在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)
答案 0 :(得分:3)
BaruchButton
不是Bool
。你想要BaruchClicked
。
直接针对true
或false
进行检查并不常见。与false
的比较最好通过简单的否定来完成:
if !(CooperClicked || TheNewSchoolClicked || BaruchClicked || FITClicked || SVAClicked) {
}