我想知道是否有可能实现这样的事情。
我有一个像这样的Playground:
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
需要默认实现中的所有内容以及其他附加内容怎么办?
这有些类似于在class
中调用super.
方法来满足实现每个属性等要求,但我看不到在structs
中达到相同效果的可能性。
Foo.testPrint(self)()
- 问题在于它由于分段错误而失败(在7.0 GM和7.1 beta上进行了测试)。 - Antonio