protocol Cloner {
func cloneSelf(thingBeingCloned t: Self) -> Self
}
final class Sheep : Cloner {
func cloneSelf(thingBeingCloned t: Sheep) -> Sheep {
let newSheep = Sheep.init()
return newSheep
}
}
如果我使用关键字' final'在课前羊离开时,编译器对我大吼大叫。我收到错误:
method 'cloneSelf(thingBeingCloned:)' in non-final class 'Sheep' must return `Self` to conform to protocol 'Cloner'
好的..然后我听到了,我将返回值更改为Self而不是Sheep,然后我又得到了另一个错误:
error: cannot convert return expression of type 'Sheep' to return type 'Self'