I have a protocol, where a function is defined, the return type of a function is a SuperclassType
.
In a class which conforms to the protocol I'm trying to define this function, but with a SubclassType
return type.
Compiler tells me, that this class does not conform to the protocol, because obviously SubclassType
!= SuperclassType
protocol SomeProtocol {
func someFunction(someParameter:SomeType) -> SuperclassType?
}
class SomeClass : SomeProtocol {
func someFunction(someParameter:SomeType) -> SubclassType? {
...
}
}
class SubclassType : SuperclassType { }
Common sense tells me, though, that SubclassType
should be a suitable substitute for a SuperclassType
in this matter.
What am I doing wrong?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…