当我将代码从swift 2.3转换为swift 3.0时,我有一个扩展实现问题。 问题陈述: -Swift 3.0扩展 - 方法没有在Child类中调用
1)每个继承类要求的协议实现
2)不能够调用它们在扩展已经实现的方法。
请检查以下代码以获取更多理解。
protocol MyExtension {
static func addTwoNumber(number1: Double, number2: Double)
}
extension MyExtension {
static func addTwoNumber(number1: Double, number2: Double) {
//implementation
}
static func subTractTwoNumbers(number1: Double, number2: Double) {
//implementation
}
}
internal class firstClass: MyExtension {
static func multiplyTwoNumbers(number1: Double, number2: Double) {
//implementation
// if I call subTractTwoNumbers in this class it is giving me an error
subTractTwoNumbers(10, 10)
//and asking me to implement protocol method as well ie
//static func addTwoNumber(number1: Double, number2: Double)
}
}
请让我知道,我做错了什么。
始终使用Xcode中建议使用属性和方法。写作func可能会有问题。 –