Swift Error: Binary operator '&&' cannot be applied to two 'Bool' operands

前端 未结 2 482
清酒与你
清酒与你 2020-12-16 11:35

There obviously has to be a way to AND or OR multiple booleans.

I\'m getting this error trying to write a function like this...

func isLocationWithi         


        
2条回答
  •  轮回少年
    2020-12-16 12:20

    While the other answer has some really interesting points, in this particular case, adding a return type to your function solves it.

    func isLocationWithinView(location: CGPoint, view: UIView) -> Bool {
        let a = true
        let b = false
        return a && b // Error: Binary operator '&&' cannot be applied to two 'Bool' operands
    }
    

    This would return true if a were true, and if not, it would look to b (lazy evaluation).

提交回复
热议问题