[swift-evolution] Access level control on setter
Derrick Ho
wh1pch81n at gmail.com
Fri Feb 10 14:35:34 CST 2017
Just for the sake of completeness... :)
open open(set) var open_open = ""i
open public(set) var open_public = ""
open internal(set) var open_internal = ""
open fileprivate(set) var open_fileprivate = ""
open private(set) var open_private = ""
public public(set) var public_public = ""
public internal(set) var public_internal = ""
public fileprivate(set) var public_fileprivate = ""
public private(set) var public_private = ""
internal internal(set) var internal_internal = ""
internal fileprivate(set) var internal_fileprivate = ""
internal private(set) var internal_private = ""
fileprivate fileprivate(set) var fileprivate_fileprivate = ""
fileprivate private(set) var fileprivate_private = ""
private private(set) var private_private = ""
On Fri, Feb 10, 2017 at 12:36 PM Adrian Zubarev via swift-evolution <
swift-evolution at swift.org> wrote:
> 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
>
> _______________________________________________
> 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/d63efe94/attachment.html>
More information about the swift-evolution
mailing list