合并所有子类中的属性以输入SWIFT的父类?

时间:2014-10-21 20:17:43

标签: swift properties subclass combiners

class example {    //parent class
    var one:Int = 10  //i want all subclass variableOne to be added to this
    var two:Int = 20  //i want all subclass variableTwo to be added to this

    init () {
    }
}

class subClassOne : example {  //subclass one
    var variableOne:Int = 30  //properties i want to add to parent properties
    var variableTwo:Int = 30  //properties i want to add to parent properties

    override init () {
        super.init ()
        super.one = one + variableOne
        super.two = two + variableTwo
    }
}

class subClassTwo {
    var variableOne:Int = 20  //properties i want to add to parent properties
    var variableTwo:Int = 20  //properties i want to add to parent properties

    override init () {
        super.init ()
        super.one = one + variableOne
        super.two = two + variableTwo
    }
}

我希望将所有子类variableOne添加到父类属性1

我还希望将所有子类variableTwo添加到父类2

0 个答案:

没有答案