protocol base{
var number:Int{get};
mutating func changeNum();//如果protocol不写mutating那么struct、enum实现此协议将会报错
}
struct Derive:base {
var number = 1;
mutating func changeNum(){
number = 2;
}
}
var d:Derive = Derive()
println(d.number);
d.changeNum();
println(d.number);
原文链接:https://www.f2er.com/swift/326867.html