How to make a protected (e.g. ruby) variable or function in Swift? I know that Swift has only 3 levels, but nevertheless it is possible?
Access levels
Swift provides three different access levels for objects inside your code. These access levels relate to the source file in which the entity is defined, and also relative to the module that the source file belongs to.
- Open access allows entities to be used in any source file from their defining module, as well as in the source file from another module that imports the defining module. Usually you use open access when specifying the public interface on the framework.
- Internal access allows an entity to be used in any source file from their module definition, but not in any source file outside this module. You usually use internal access when defining applications or internal frameworks.
- Private access restricts the use of an object to its own defining source file. Use private access to hide implementation details of a particular piece of functionality.
Public access is the highest (least restrictive) access level and private access is the lowest (or most restrictive) access level
Currently, I see only one solution: write a parent class with a private modifier and a child class in one file, but this will be painful.
source share