In Swift, protected methods and properties are not accessible outside of the class or its subclasses. However, we can define a "helper" method inside the class that creates and returns an instance of that class, and then call the protected static method on it.
Here's an example:
main.swift296 chars13 linesIn this example, we define a protected static method myMethod on the MyClass class. We also define a method callProtectedMethodOnInstance that creates an instance of MyClass and then calls myMethod on its dynamic type.
Note that we use dynamicType to get the type of the object at runtime, since instance is declared as a MyClass but may actually be an instance of a subclass that also defines myMethod.
gistlibby LogSnag