Member-only story
Access Control in Swift
Getting confused about the open, public , private keywords in swift? No worries. You are in the right place. Lets dive into the content without wasting time. As the name suggests, access control restricts or enables access to some part of your code from the code in other other modules or files.
Types of access specifiers :
- Open : Using this keyword, you can access the properties and functions within the same module and also outside the module. Subclassing is possible outside the module.
Lets see this with an example. I have created a new project to explain this.
I have added a new package named “AccessControl”. Below is the image.
Now, I create a class named TestAccessibility to test the accessibility outside the module.
Here, as you can see we are able to extend the “AccessControl” class (which is inside the package) from outside the module and override the “getAccessSpecifierType” method. The compiler does not throw any error.
2) Public : The difference between public and open is we can access the properties and methods from outside the module but we will not be…









