覆盖Swift 2.0中的类方法会产生错误和崩溃

时间:2015-11-02 10:13:15

标签: swift class methods swift2

我试图在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)
    }
}

0 个答案:

没有答案