[swift-evolution] [Proposal Draft] Remove open Access Modifier

Joanna Carter joanna at carterconsulting.org.uk
Wed Feb 22 05:27:48 CST 2017


> What I have done for this case is have a protocol with several private conforming Structs, and then wrap it all in a public final class which wraps a boxed instance of one of the conformers.
> 
> Here is some code: https://gist.github.com/jonhull/b9cd8a50abca16ea49eade2c91edf8a2

I notice that you declare several private (fileprivate ?) types in the same file as the type that uses them.

Since we are able to nest types, why wouldn't that be a better solution to the "need" for fileprivate to hiding of related types instead of using the file scope?

e.g.

public final class Source
{
  private struct ConstantSource { }
  
  private struct OrderedSource { }
  
  private struct RandomOrderedSource { }
  
  func useConstant()
  {
    let _ = ConstantSource()
  }
  
  func useOrdered()
  {
    let _ = OrderedSource()
  }
  
  func useRandomOrdered()
  {
    let _ = RandomOrderedSource()
  }
}

I suppose, having got used to using nested types in C# is maybe why I find it hard to understand why we need the 'fileprivate' scope.

--
Joanna Carter
Carter Consulting



More information about the swift-evolution mailing list