0

Is there any way to let the method of the superclass be overrided, but not called directly?

For example: A inherited from B. There is two methods. One is final and must be called, second is overridable but shouldn't be called, only override.

I tried @available and private but that don't fit. I think that it can be reached by delegate, but maybe there is another way?

Nike Kov
  • 12,630
  • 8
  • 75
  • 122
  • What do you mean by "one is final and must be called"? Who should call this function, itself? – aunnnn Feb 24 '18 at 17:11

1 Answers1

1

For example, you can throw an error in your method that will say that this method shouldn't be called and child class should override it. But, of course, it is no compile time restriction, only runtime.

Also it has sense for you to read discussion here: Abstract functions in Swift Language

Serega
  • 630
  • 1
  • 4
  • 12