class ca{
var count:Int{
get{
return 1;
}
set{
self.count = newValue;
}
}
func describe()->String{
return "ca";
}
}
class cb: ca {
override func describe() -> String {
return "cb";
}
override var count:Int{
get{
return 2;
}
set{ //引起了递归调用,未找到正确写法
super.count = newValue + 1;
}
}
}
var v1 = cb();
println(v1.describe());
v1.count = 2;
println(v1.count);
原文链接:/swift/326937.html