swift protocol mutating

前端之家收集整理的这篇文章主要介绍了swift protocol mutating前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

protocol base{

var number:Int{get};

mutating func changeNum();//如果protocol不写mutating那么structenum实现此协议将会报错

}


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

猜你在找的Swift相关文章