如果需要更改访问者的可见性或对其进行注释,但不需要更改默认实现,则可以定义访问者而不定义其主体:var setterVisibility:String =“abc” private set // setter是私有的,具有默认实现
1
您可以使用以下语法:
var setterVisibility: String = "abc" // Initializer required, not a nullable type
private set // the setter is private and has the default implementation
2 回答
您可以定义访问者而无需定义其正文:
在这种情况下,setter是私有的 .
来自the docs:
您可以使用以下语法:
请参考官方here
这也是this question的倍增