//: Playground - noun: a place where people can play
importCocoa
varstr ="Hello,playground"
structpoint{
varx =0;
vary =init(x:Int,y:Int){
self.x= x;
y= y;
println("init");
}
funcgetCenter()->Int{
return(x+y)/2;
}
mutatingfuncaddOffset(deltaX:Int){//mutating结构体成员变量改变写此特性
x+=deltaX;
y+=deltaY;
}
}
//var v1 = point(x:2,y:3);//没有构造函数时,可以这样调用
//println("\(v1.x),\(v1.y)");
//var v2 = point();//没有构造函数时,可以这样调用
//println("\(v2.x),\(v2.y)");
varv3 =point(x:4,y:5);
"\(v3.x),\y)");
varv4 =v3.getCenter();
addOffset(2,deltaY:2);
原文链接:https://www.f2er.com/swift/326948.html