Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 366
shokuroff Avatar asked Mar 20 '17 07:03

shokuroff


1 Answers

  • Internal - This is default access specifier in swift. With this we can access data members and member functions in the same module (target).

  • Public - This is where you can access all data members and member functions within same module and outside of it. But you can't subclass or override outside the module.

  • Open - same as public, only difference is you can subclass or override outside the module.

  • Fileprivate - As the name say's, data members and member functions are accessible within the same file.

  • Private - This is where you can have access within the scope of function body or class.

like image 125
rahul katore Avatar answered Oct 19 '22 20:10

rahul katore