title: How iterate through all properties of different classes in Swift?
body: <p>Let's say I have one parent class called Car with some properties and one method which actually does nothing.</p>
  
  <pre><code>class Car {
      var brandName : String
      var yearOfCreation : Int
      var color : String
      var numberOfDoors : Int
  
      func manipulateWithCar() {
      }
  
      init(brandName : String, yearOfCreation : Int, color : String, numberOfDoors : Int) {
          self.brandName = brandName
          self.yearOfCreation = yearOfCreation
          self.color = color
          self.numberOfDoors = numberOfDoors
      }
  }
  </code></pre>
  
  <p>And I have two child classes called SportCar and TankerCar. They have their unique properties and also the method from parent class is overridden and now it does something.</p>
  
  <pre><code>class SportCar : Car {
      var turbo : Bool
      var nitrousOxideEngine : Bool
  
      override func manipulateWithCar() {
          print("Putting turbo on your car...")
          turbo = true
      }
  
      init(brandName: String, yearOfCreation: Int, color: String, numberOfDoors: Int, turbo : Bool, nitrousOxideEngine : Bool) {
          self.turbo = turbo
          self.nitrousOxideEngine = nitrousOxideEngine
          super.init(brandName: brandName, yearOfCreation: yearOfCreation, color: color, numberOfDoors: numberOfDoors)
      }
  }
  </code></pre>
  
  <p>And also there is one enum for the method. This is not important but you just want to keep it as in the homework.</p>
  
  <pre><code>enum TankerForm {
      case cilindrical
      case quadratic
  }
  
  class TankerCar : Car{
      var tankerFilledSize : Int
      var tankerForm : TankerForm
  
      init(brandName : String, yearOfCreation : Int,
           color : String, numberOfDoors : Int, tankerVolum : Int, tankerForm : TankerForm) {
          self.tankerForm = tankerForm
          self.tankerFilledSize = tankerVolum
          super.init(brandName: brandName, yearOfCreation: yearOfCreation, color: color, numberOfDoors: numberOfDoors)
      }
  
      override func manipulateWithCar() {
          print("Loading 200 gallon of oil")
          tankerFilledSize = 200
      }
  }
  </code></pre>
  
  <p>Creating some objects...</p>
  
  <pre><code>var kia = Car(brandName: "Rio", yearOfCreation: 2015, color: "Green", 
  numberOfDoors: 4)
  
  var toyota = Car(brandName: "Corolla", yearOfCreation: 2015, color: 
  "Red", numberOfDoors: 4)
  
  var lamborgini = SportCar(brandName: "Aventador", yearOfCreation: 2018, 
  color: "Black", numberOfDoors: 2, turbo: false, nitrousOxideEngine: 
  false)
  
  var mazeratti = SportCar(brandName: "Ghibli", yearOfCreation: 2017, 
  color: "Red", numberOfDoors: 4, turbo: true, nitrousOxideEngine: false)
  
  var kamaz = TankerCar(brandName: "Kamaz", yearOfCreation: 2007, color: 
  "Yellow", numberOfDoors: 2, tankerVolum: 0, tankerForm: .cilindrical)
  
  var belaz = TankerCar(brandName: "Belaz", yearOfCreation: 2003, color: 
  "White", numberOfDoors: 2, tankerVolum: 0, tankerForm: .quadratic)
  </code></pre>
  
  <p>Creating arrays with objects...</p>
  
  <pre><code>var carrsArray : [Car] = [kia, toyota]
  var sportCarsArray : [SportCar] = [lamborgini, mazeratti]
  var tankerCarsArray : [TankerCar] = [kamaz, belaz]
  </code></pre>
  
  <p>And printing all the properties for Car class objects using for loop...</p>
  
  <pre><code>for value in carrsArray {
      print("This car is \(value.brandName)")
      print("The color is \(value.color)")
      print("The car has \(value.numberOfDoors) doors")
      print("The year of creation is \(value.yearOfCreation)")
      print(" ")
  }
  </code></pre>
  
  <p>Printing all the properties for SportCar class objects using for loop...</p>
  
  <pre><code>for value in sportCarsArray {
      print("This car is \(value.brandName)")
      print("The color is \(value.color)")
      print("The car has \(value.numberOfDoors) doors")
      print("The year of creation is \(value.yearOfCreation)")
      if value.nitrousOxideEngine == true {
          print("This car has Nitrous Oxide Engine")
      } else {
           print("There is no Nitrous Oxide Engine on this car.")
      }
      if value.turbo == true {
          print("This car has turbo")
      } else {
          print("There is no turbo in this car.")
      }
      print(" ")
  }
  </code></pre>
  
  <p>Printing all the properties for TankerCar class objects using for loop...</p>
  
  <pre><code>for value in tankerCarsArray {
      print("This car is \(value.brandName)")
      print("The color is \(value.color)")
      print("The car has \(value.numberOfDoors) doors")
      print("The year of creation is \(value.yearOfCreation)")
      print("The tanker is filled with \(value.tankerFilledSize) lb of oil.")
  
      if value.tankerForm == .cilindrical {
          print("This car has cilindrical tanker form.")
      } else {
          print("This car has quadratic tanker form.")
      }
      print(" ")
  }
  </code></pre>
  
  <p>Now the question. Is there any way to print all the properties for different classes? I tried to create a new array of three arrays:</p>
  
  <pre><code>var allClassesArrays = [carrsArray, sportCarsArray, tankerCarsArray]
  </code></pre>
  
  <p>But during iteration, it was able to get all the properties of the parent class.</p>