如何在swift中覆盖计算属性

时间:2015-01-16 02:01:04

标签: swift properties override

我只是尝试了一下快捷的新功能Overriding Property Observers

class B {
    var c:Int = 3 {
        didSet {
           c = 5
        }
    }
}
class C: B {

    override var c:Int = 9 {
        didSet {
            c = 10
        }
    }
}

但会引发编译错误:

Playground execution failed: super.init called 
multiple times in initializerinteger overflows 
when converted from 'Builtin.Int32' to 'Builtin.Int8'

0 个答案:

没有答案