0
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
    }
}

I want all subclass variableOne to be added to parent class property one

I also want all subclass variableTwo to be added to parent class two

David Berry
  • 40,941
  • 12
  • 84
  • 95
  • 2
    I am not sure if it is the formatting or what, but your question is very unclear. – AdamBT Oct 21 '14 at 20:30
  • unclear, what do you try to do? – Daij-Djan Oct 21 '14 at 21:06
  • What you have here should "work" but it's not at all clear what you want to do, so it's not at all clear that it will do what you want. Perhaps you could give some examples of expected results. – David Berry Oct 21 '14 at 22:46
  • I'm no expert in swift, but isn't subClassTwo it's own class? I'm not seeing where in inherits from example or subClassOne. – Joe Million Oct 21 '14 at 23:00

0 Answers0