Apple removed & = operator from Swift 1.2 for booleans?

Xcode 6.3 returns a compilation error in &=with boolean values.

'&=' is unavailable: use the '&&' operator instead

example:

var myBool = false
myBool &= true

Any idea why it was deleted?

+1
source share
1 answer

I would suggest that they delete it because it &=is a bitwise operator for other types, so for it a logical operator in Boolean languages ​​would be inconsistent (and the bitwise operation Boolprobably frowned), so really it should be &&=. What is not defined is possibly because it is a minimal utility. But if you want this:

infix operator &&= {
    associativity right
    precedence 90
    assignment
}

func &&=(inout lhs: Bool, @autoclosure rhs: ()->Bool) {
    lhs = lhs && rhs
}

var myBool = true
myBool &&= false
+2
source

All Articles