【发布时间】:2017-04-17 06:05:52
【问题描述】:
我需要从 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中返回一个值...
-
为什么要从集合中返回任何值?它有什么用?
标签: swift swift3 return-value getter-setter