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 
([email protected]) 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
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to