[swift-evolution] Default access control / Access control blocks

Joe Groff jgroff at apple.com
Tue Mar 29 11:23:04 CDT 2016


> On Mar 29, 2016, at 7:07 AM, Dan Raviv via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hi,
> 
> While implementing a function which returns a struct as a result, I ran into having to make not only the struct public but also its members, otherwise external callers are exposed to the struct but not to its members.
> 
> 1) Wouldn't it make sense for a public struct to have its fields be public by default? Individual fields's access could still be overridden as internal.
> 
> 2) If the answer to 1 is no, does it make sense to have to specify the access level for each individual field which shouldn't have default access level? Why not have an access control block, e.g.
> 
> public struct Result {
>     public {
>         field1: Double
>         field2: Int
>     }
> }
> 
> Please excuse me if similar functionality already exists and I'm not aware.

For declarations that can be made in extensions, you can use `public extension` for this. That doesn't include stored properties, though we've discussed relaxing that restriction.

-Joe



More information about the swift-evolution mailing list