I have a Child class that contains methods that I define and methods inherited from its Parent class. I want some of the methods from Parent to be unavailable to the user or at least generate a compile error/warning when used. Example:
class Parent {
public func secretMethod() { // Don't want anyone to use
}
}
class Child: Parent {
public func overtMethod() { // Fine with people using
}
}
Child.init().overtMethod() // Fine
Child.init().secretMethod() // Not Fine. Should not be viewable/useable/accessible
I cannot change the parent class. How I long to be able to set secretMethod
to private
. Swift doesn't allow restricting the access level when overriding functions, so I can't set secretMethod
to private
in the Child class either.
So far I have been using @available
to mark the method with a compile warning and message, but I am hoping that there is a better way? I considered overriding and throwing an error, but that can't be done if the original method isn't marked throws
.
Thank you.
Edit: I also cannot override the secretMethod to make it unavailable. The Child class needs to access it.