Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 1.2 (Xcode 6.3) removed xor '^' operator for Bool value?

This sample code on Xcode 6.3 ...

var str1 = ""
var str2 = ""
if str1.isEmpty ^ str2.isEmpty {
  // do something.
}

displays the following error.

'^' is unavailable: use the '!=' operator instead

I cannot find the spec in Apple documentation. Is this specification (and I'll have to lump it)?

like image 290
Mitsuaki Ishimoto Avatar asked Apr 10 '15 07:04

Mitsuaki Ishimoto


2 Answers

Assuming you are trying to use a logical XOR, a != should serve your purpose. The ^ is a bitwise XOR. So makes sense that Apple removed it for bool values.

like image 92
lostInTransit Avatar answered Sep 19 '22 11:09

lostInTransit


It's clearly intentional:

$ echo ':print_module Swift' | swift -deprecated-integrated-repl | fgrep "use the '!=' operator instead"

shows:

@availability(*, unavailable, message="use the '!=' operator instead") func ^=(inout lhs: Bool, rhs: Bool)
@availability(*, unavailable, message="use the '!=' operator instead") func ^(lhs: Bool, rhs: Bool) -> Bool
like image 39
rintaro Avatar answered Sep 18 '22 11:09

rintaro