Swift 1.2(Xcode 6.3)删除了xor'^'运算符的Bool值?

Mit*_*oto 16 xcode ios swift xcode6.3

Xcode 6.3上的示例代码...

var str1 = ""
var str2 = ""
if str1.isEmpty ^ str2.isEmpty {
  // do something.
}
Run Code Online (Sandbox Code Playgroud)

显示以下错误.

'^' is unavailable: use the '!=' operator instead
Run Code Online (Sandbox Code Playgroud)

我在Apple文档中找不到该规范.这个规范(我必须把它搞砸)?

los*_*sit 28

假设您正在尝试使用逻辑XOR,则!=应该满足您的目的.这^是一个按位异或.因此,苹果公司为了bool价值而取消了它.

  • @jowie xor同时没有超过两个元素的定义,您期望它如何工作? (6认同)
  • @jowie(a!= b)!= c应该这样做. (6认同)
  • @jowie XOR是关联的.`(a⊕b)⊕c`=`a⊕(b⊕c)`,所以你可以选一个 (3认同)

rin*_*aro 11

这显然是故意的:

$ echo ':print_module Swift' | swift -deprecated-integrated-repl | fgrep "use the '!=' operator instead"
Run Code Online (Sandbox Code Playgroud)

说明:

@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
Run Code Online (Sandbox Code Playgroud)