[swift-evolution] [Proposal] Protected Access Level
Charles Srstka
cocoadev at charlessoft.com
Mon May 30 01:28:15 CDT 2016
> On May 28, 2016, at 8:11 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>
> But `protected` is quite different from other access levels; it does not limit the visibility of the symbols, but rather their use. And protocols face the same sort of problem as classes, where certain members are essentially override hooks and shouldn't be called directly outside a particular scope.
>
> So I think we ought to allow `accesslevel(call)`, but not a plain `accesslevel`:
>
> public fileprivate(call) func layoutSubviews()
> internal fileprivate(call) func privateSubclassingHook()
> public internal(set: call) var x = 20
> internal(call) func protocolConformanceHook()
> fileprivate(set: call) var onlyProtocolSetsThis: Int { get set }
Given that this is almost identical to the pitch I floated to the list some months ago, all the way down to the fileprivate(call) syntax (well, back then “fileprivate” was “private”, so it was private(call)), I’m +1 on this.
> On May 29, 2016, at 6:55 PM, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>
> The thing is, though, the contents of the sharps drawer are *still* sharp even if you're old enough to use a knife. And similarly, APIs like the `state` setter are *still* dangerous even if you've subclassed `UIGestureRecognizer`. To be sure, it is more likely that you'll *need* to set `state`, but it's still not something you should do carelessly or without understanding the consequences.
This, though, reads like “The 17-year-old might cut himself with a knife, even though he *needs* the knives to help with the cooking. So, let’s give knives to the newborn!”
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160530/accba957/attachment.html>
More information about the swift-evolution
mailing list