这不能在 Swift 5.10 中编译。
protocol Common {
func func1() -> Common
func func2() -> Common
func func3() -> Common
func func4() -> Common
}
struct Model: Common {
func func1() -> any Common {self}
func func2() -> Common {self}
func func3() -> Self {self} // Not conformant
func func4() -> Model {self} // Not conformant
}
我不清楚为什么 Self 和 Model 不符合 Common 协议。我也不会想到添加“any”,但这就是 Xcode 的“fix”生成的。
协议“准确地”描述了采用者必须说的话。 func func3() -> Common
表示采用者必须按字面意思说
func func3() -> Common
才能保持一致。