0

I have a class, which is intended to be subclassed. I tried to use required for the methods that the subclass must implement.

However, that's reserved for init.

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • 2
    I don't think swift supports this but you can implement a protocol, which is really easy, although any class that comes from the parent class implementing the protocol can ignore the protocol requireds. Check here for more ideas. http://stackoverflow.com/questions/24111356/swift-class-method-which-must-be-overridden-by-subclass – AtheistP3ace Jun 25 '16 at 02:39
  • If you want Xcode to throw an error at compule time, it's not possible AFAIK. If you want the app to fail at runtime if the subclass doesn't override the method, you can add this code in the method implementation of the base class: `fatalError("subclasses must override without calling super")`. Not very elegant IMO. – Nicolas Miari Jun 25 '16 at 03:11
  • Both comments are correct. See also http://stackoverflow.com/questions/24110362/abstract-functions-in-swift-language – Feldur Jun 25 '16 at 06:52

0 Answers0