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

合并所有子类中的属性以输入到SWIFT的父类中?,swift,properties,subclass,combiners,Swift,Properties,Subclass,Combiners,我希望所有子类variableOne都添加到父类属性one中 我还希望所有的子类variable2都被添加到父类2中我不确定是格式还是什么,但你的问题很不清楚。不清楚,你想做什么?你在这里所做的应该“起作用”,但你想做什么却一点也不清楚,所以根本不清楚它会做你想做的事情。也许你可以给出一些预期结果的例子。我不是swift方面的专家,但子类2不是它自己的类吗?我不知道从示例或子类中继承了什么。 class example { //parent class var one:Int =

我希望所有子类variableOne都添加到父类属性one中


我还希望所有的子类variable2都被添加到父类2中

我不确定是格式还是什么,但你的问题很不清楚。不清楚,你想做什么?你在这里所做的应该“起作用”,但你想做什么却一点也不清楚,所以根本不清楚它会做你想做的事情。也许你可以给出一些预期结果的例子。我不是swift方面的专家,但子类2不是它自己的类吗?我不知道从示例或子类中继承了什么。
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
    }
}