[swift-evolution] Access level control on setter

Pasquale Ambrosini pasquale.ambrosini at gmail.com
Fri Feb 10 11:33:25 CST 2017

Hi guys,
My idea is simple, put an access level control token to the setter of a var

Right now, we are likely to do something like this in order to hide the setter:

fileprivate var _timestamp: Date = Date()
public var timestamp: Date {
	return self._timestamp

The idea is to do it without using another var, like this:

public var timestamp: Date {
	get { return self._timestamp }
	fileprivate set(newValue) { _timestamp = newValue }

In this way the setter will be available “locally” in the file but it will not be accessible from outside.
The only problem that I can see is how to reference the var itself? As you can see I used  “_timestamp” like Objective-C, but there should be another way to do reference it.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170210/3099ea59/attachment.html>

More information about the swift-evolution mailing list