Is there a way to mark some Swift functions as implementing some protocol functions so that if the protocol's signature changes, the compiler can mark implementations as an error.
For instance, consider this example where I have a default implementation of the Foo
protocol for UIViewController
instances, and I want to override it for a custom Bar
class that is a subclass of UIViewController
.
// V1
protocol Foo {
func number() -> Int
}
extension Foo where Self: UIViewController {
func number() -> Int {
return 0
}
}
// Overrides the default implementation
extension Bar: Foo {
func number() -> Int {
return 1
}
}
Now, the protocol evolves to:
// V2
protocol Foo {
func numberV2() -> Int
}
extension Foo where Self: UIViewController {
func numberV2() -> Int {
return 0
}
}
// I think I override the default implementation but not anymore.
// => error prone, no error from the compiler
extension Bar: Foo {
func number() -> Int {
return 1
}
}
How can I help my Bar
extension be aware that the number
function is no longer relevant for the Foo
protocol?