Search code examples
swiftoopinheritancepublicinternal

Swift 3: The difference between Public and Internal access modifiers?


I read the Apple's reference about access modifiers in Swift 3. I read also about the same on stackoverflow but I didn't get an answer as the person who asked. As I understood correctly, there are four levels:

  1. Open, Public
  2. Internal
  3. Fileprivate
  4. Private

I created the schemes for myself to understand a difference between all these modifiers and uploaded here. As you can see, there are no differences between Public and Internal modifiers.. However they're on different levels. Any idea would be appreciated!


Solution

  • Your diagram is just incorrect.

    Public members of A.swift and B.swift are available to C.swift and D.swift. The only restriction is that classes can't be subclassed (they would need to be open.