我想知道是否有可能做到这一点。
我有一个这样的游乐场:
protocol Foo {
func testPrint()
}
extension Foo {
func testPrint() {
print("Protocol extension call")
}
}
struct Bar: Foo {
func testPrint() {
// Calling self or super go call default implementation
self.testPrint()
print("Call from struct")
}
}
let sth = Bar()
sth.testPrint()
我可以在 extension中提供一个默认实现,但是如果 Bar需要默认实现中的所有内容以及其他内容,那该怎么办?
这有点类似于在 classes 中调用 super.方法来满足实现每个属性等等的要求,但是我看不到在 structs中实现同样的要求的可能性。