I got an error while performing a bitwise operation on two boolean values. Error :"Binary operator '|=' cannot be applied to two 'Bool' operands"
func checkAvailability(available:Bool) -> Bool{
var bChanged = false
bChanged |= available //"Binary operator '|=' cannot be applied to two 'Bool' operands"
return bChanged
}
Please any one help me to solve the problem...
You could define it yourself by overloading the operator:
Swift 2:
func |= (inout left: Bool, right: Bool) {
left = left || right
}
Swift 3:
func |= (left: inout Bool, right: Bool) {
left = left || right
}
This is a simple expansion of Lew's answer to include the other two "missing" operators.
// A couple of operators that exist in C# and Java but are missing from Swift.
public func |= (leftSide : inout Bool, rightSide : Bool) {
leftSide = leftSide || rightSide
}
public func &= (leftSide : inout Bool, rightSide : Bool) {
leftSide = leftSide && rightSide
}
public func ^= (leftSide : inout Bool, rightSide : Bool) {
leftSide = leftSide != rightSide
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With