In Swift, you cannot directly access a protected static property on an instance of a class outside of the class hierarchy. However, you can create a getter function for the property in the superclass that returns the value of the protected static property.
Here's an example:
main.swift435 chars17 lines
In this example, Superclass
has a protected static property protectedStaticProperty
, and getProtectedStaticProperty()
is a function that returns the value of that property. Subclass
inherits from Superclass
and can access the protected function getProtectedStaticProperty()
. By calling this function on an instance of Subclass
, you can indirectly access the protected static property protectedStaticProperty
.
gistlibby LogSnag