19

Xcode 6.3 上的此示例代码...

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

显示以下错误。

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

我在 Apple 文档中找不到规范。是这个规范吗(我不得不把它混为一谈)?

4

2 回答 2

30

假设您正在尝试使用逻辑 XOR,a!=应该可以满足您的目的。是^按位异或。因此,Apple 将其删除为 bool 值是有道理的。

于 2015-04-10T07:39:52.120 回答
14

这显然是故意的:

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

显示:

@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
于 2015-04-10T14:02:12.910 回答