我试图在Swift 2.0中覆盖超类方法,但是我收到错误并且崩溃,所以代码不会原谅自己。
以下是创建问题的特定代码。
override func discountedPrice (percentage: Double = 10.0) -> Double {
return super.discountedPrice(percentage)
}
超类和子类
import UIKit
class Product {
let title : String
var price : Double = 0.0
init (title: String, price: Double) {
self.title = title
self.price = price
}
func discountedPrice (percentage: Double) -> Double {
return price - (price * percentage/100)
}
}
enum Size{
case Small, Medium, Large
init () {
self = .Small
}
}
class Clothing: Product {
var size = Size()
let designer : String
init (title: String, price: Double, designer :String){
self.designer = designer
super.init(title: title, price: price)
}
override func discountedPrice (percentage: Double = 10.0) -> Double {
return super.discountedPrice(percentage)
}
}