There is no way to do it on the compile time in Swift. The feature of enforcing method override is not present in Swift.
But there is a work around.
You can do that by putting a fatal error fatalError("Must Override")
.
Consider the following example.
class Base {
func method1() {
fatalError("Must Override")
}
func method2() { }
}
class Child: Base {
override func method1() { }
func method3() {
fatalError("Must Override")
}
}
class GrandChild: Child {
func method1() { }
func method3() { }
}
But the above method will not give any compile time errors. For that there is another workaround.
You can create a protocol.
protocol ViewControllerProtocol {
func method1()
func method3()
}
typealias ViewController = UIViewController & ViewControllerProtocol
So if you implement this protocol and do not implement the methods compiler will generate an error.
As a feature of protocols in Swift you can also provide a default implementation of the methods in a protocol extension.
Hope this helps.