[swift-evolution] Access level control on setter

Adrian Zubarev adrian.zubarev at devandartist.com
Fri Feb 10 11:36:09 CST 2017


How about just using this?

struct MyType {
    public fileprivate(set) var timestamp: Date
}


-- 
Adrian Zubarev
Sent with Airmail

Am 10. Februar 2017 um 18:33:35, Pasquale Ambrosini via swift-evolution (swift-evolution at swift.org) schrieb:

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.


Cheers,

Pascal






_______________________________________________
swift-evolution mailing list
swift-evolution at swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170210/dba776b5/attachment.html>


More information about the swift-evolution mailing list