I\'m creating several NSView
classes, all of which support a special operation, which we\'ll call transmogrify
. At first glance, this seems like t
check this solution here... Swift - class method which must be overridden by subclass
This solution allows to inherit from a class and also to have the protocol's compile time check. :)
There is a workaround by using associated types to enforce the subclass:
protocol TransmogrifiableView {
associatedtype View: NSView = Self
func transmogrify()
}
class MyView: NSView, TransmogrifiableView { ... } // compiles
class MyOtherClass: TransmogrifiableView { ... } // doesn't compile