I was surprised and *pleased* to find that I could override a return type on a function, though the documentation says the compiler checks for a "match." This matching seems to treat the return type with subtle special consideration--but where is this documented? What am I missing?
Playground code:
class A {
}
class B : A {
}
class D {
func arbitraryFactory() -> A {
return A()
}
func identify(anID: A) {
print(anID)
}
}
class E : D {
override func arbitraryFactory() -> B { // subclass as return type similar enough to require "override"
return B()
}
func arbitraryFactory() -> E { // different enough not to require "override"
return E()
}
func identify(anID: B) { // subclass as input different enough not to require "override"
print(anID)
}
}