19

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)?

Mitsuaki Ishimoto
  • 3,162
  • 2
  • 25
  • 32

2 Answers2

30

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.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
14

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
rintaro
  • 51,423
  • 14
  • 131
  • 139