问题
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)?
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/29555569/swift-1-2-xcode-6-3-removed-xor-operator-for-bool-value