1
我需要从setter中返回一个字符串,我该怎么做?下面是代码:设置器中的快速返回值
func example()->String{
var _a = 5
var a: Int{
set(newValue){
_a = newValue
if _a < 0{
//return a string here!!
}
}get{
return _a
}
}
a = 0
}
setter只设置值不返回。但是你可以在你的'example'方法中使用变量 –
从逻辑上讲,你不能*返回* setter中的值* ... –
为什么你想要返回集合中的任何值?它有什么用处? – Sahil