var a = 1;
var b = a;
a=2;
println(@H_403_21@"\@H_403_21@(a@H_403_21@),\@H_403_21@(b@H_403_21@)");//2,1
struct cs{
var v:Int = 99;
}
var i = cs();
var j = i;
i.v = 98;
println(@H_403_21@"\@H_403_21@(i.v@H_403_21@),\@H_403_21@(j.v@H_403_21@)");//98,99
class ca{
var v:Int;
init(var a:ca){//拷贝构造实现传值
self.v = a.v;
}
init(){
v = 100;
}
}
var x = ca();
var y = x;
var z = ca(a: x);
x.v = 200;
println(@H_403_21@"\@H_403_21@(x.v@H_403_21@),\@H_403_21@(y.v@H_403_21@),\@H_403_21@(z.v@H_403_21@)");//200,200,100
//Int、struct是copy,class是引用
原文链接:https://www.f2er.com/swift/326860.html