After much to-ing and fro-ing about scopes on Swift, I, for one, am getting 
confused about exactly what effects the present scopes have on the various 
fundamental types used in Swift (protocols, classes, structs, enums, ordinal 
types)

Therefore, if you will indulge me, I would like to start a thread in which I 
will I will outline what is and what is not possible at present.

Let me start with protocols :

If I start with the lowest visibility - private


private protocol PrivateProtocol { }

private protocol DoublePrivateProtocol : PrivateProtocol
{
  var p: PrivateProtocol { get }
}

It would seem that, within the same file, private has the same meaning as 
fileprivate. Understandable to some degree but could be confusing to some.

We can both inherit from and use a private protocol as part of another private 
or fileprivate protocol

internal class Fred
{
  init() { }
  
  private var pp: PrivateProtocol
}

We can also implement or use a private protocol as part of another non-private, 
non-protocol type

internal protocol InternalProtocol : PrivateProtocol // error : Internal 
protocol cannot refine a fileprivate protocol
{
  var p: PrivateProtocol { get } // error : Property cannot be declared 
internal because its type uses a fileprivate type
}

However, we cannot either inherit from or use a private protocol as part of a 
non-private protocol. Totally understandable.

Both internal and public protocol scopes are also self explanatory, and it is 
obvious that, just as an internal protocol cannot refine or use a private 
protocol, neither can a public protocol cannot refine or use an internal one.

For this post, my only question is - why is private allowed when, in reality, 
it is fileprivate for protocols?

More to follow…
 
--
Joanna Carter
Carter Consulting

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to