原理是:一个数异或同一个数两次,结果还是那个数
int x =5,y=10; //定义两个变量
x = x^y;
y = x^y; //y=(x^y)^y
x = x^y; //x=(x^y)^x
x ^= y;
==> y ^= x; ==> x ^= y ^= x ^= y;
x ^= y;
swift 交换方法可以这样
var a = "123"
var b = "abc"
print(a,b)
(a,b) = (b,a)
print(a,b)