0

I have gone through the Apple provided document i.e https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html

Here, it explains:

Classes with public access, or any more restrictive access level, can be subclassed only within the module where they’re defined.

Internal access enables entities to be used within any source file from their defining module, but not in any source file outside of that module. You typically use internal access when defining an app’s or a framework’s internal structure.

Open classes can be subclassed within the module where they’re defined, and within any module that imports the module where they’re defined

I am not finding the exact difference between the public and Internal access.

My research includes http://www.globalnerdy.com/2014/07/23/a-first-look-at-swifts-new-access-levels/ as well. But as per swift3.3 documentation, its not clear.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
am449
  • 158
  • 11
  • 3
    Internal classes are not accessible at all outside of the defining module. Public classes are accessible outside of the defining module, but cannot be subclassed – Martin R Jun 09 '17 at 09:31
  • As said in the documentation you link to "*Open access and public access enable entities to be used within any source file from their defining module, and also in a source file from another module that imports the defining module*" :) – Hamish Jun 09 '17 at 09:33
  • 2
    Did you read this https://stackoverflow.com/questions/24003918/does-swift-have-access-modifiers ? – Martin R Jun 09 '17 at 09:34
  • Thanks Martin for this "https://stackoverflow.com/questions/24003918/does-swift-have-access-modifiers" link. Its helpful. – am449 Jun 09 '17 at 10:04
  • Possible duplicate of [Does Swift have access modifiers?](https://stackoverflow.com/questions/24003918/does-swift-have-access-modifiers) – Vadim Kotov Dec 12 '17 at 08:45

1 Answers1

2

Swift’s access control model is based on the concept of modules and source files.

A module is a single unit of code distribution—a framework or application that is built and shipped as a single unit and that can be imported by another module with Swift’s import keyword.

For example, some popular modules: Alamofire, SwiftyJson, RxSwift ... These modules you are importing into your project. All classes that are using internal access level can be used only inside these libs/ modules. You cannot use them directly in your code. But if the class is public - you can use it in your sources directly.

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
Bogdan Ustyak
  • 5,639
  • 2
  • 21
  • 16