[swift-evolution] Pre-proposal: "private(extension)" access modifier?

Austin Zheng austinzheng at gmail.com
Tue Jan 5 18:59:11 CST 2016

Hi all,

One popular use of extensions is to take the definition of a type (e.g.
MyBigClass) and to split it up over a number of files, grouping related
methods together for increased code comprehensibility. However, access
control makes doing so more difficult: members that are implementation
details and declared as 'private' can't be seen from other files.

I'd like to suggest an access modifier: "private(extension)". This follows
in the spirit of the existing "private(set)" for properties. It would work
in the following way:

- A member declared private(set) would be visible throughout the file
within which it was declared, exactly as if it had been declared "private"
- A member declared private(set) would be visible in any file containing an
extension to the member's type, throughout the entire file.
- This would only work for extensions to types declared within the same
module; it would not be meant as a way to expose impl details to other
modules or application code consuming the module.
- A property in T meant to be only gettable from other files, but settable
from extensions to T in other files, would be declared "private(set,

I think this is a reasonably elegant, small-surface-area solution to a
common problem, but I can see some potential objections:

- It adds some complexity to the access control subsystem. Maybe that
subsystem is complex enough as is.
- It might leak implementation details of a type T to code belonging to
another type or global function, residing within the same file as an
extension to T.
- Maybe there might be more elegant ways to improve or extend the access
control subsystem.

Any thoughts?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160105/b232eab8/attachment.html>

More information about the swift-evolution mailing list