[swift-evolution] [Proposal] Protected Access Level

Brent Royal-Gordon brent at architechies.com
Sun May 29 19:03:53 CDT 2016


> 1. Methods and properties that only subclasses must access, but other code has no business updating. An example of this UIGestureRecognizer. State machine type access is something where external items should not access, but internal state may require the rights to update.

But again, "external" does not necessarily mean "non-subclass", and "internal" does not necessarily mean "subclass". A particular subclass might not require access, and a helper type/function might require access.

This insight—that the type graph doesn't always reflect the boundaries of concerns—is the very basis of Swift's current access control design. It's the reason why `private` (soon to become `fileprivate`) doesn't grant visibility to extensions on the same type in different files, but *does* grant it to extensions on different types in the same file. This is an important innovation in Swift's access control design, and we shouldn't ignore it when we're thinking about `protected`.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list