title: Polymorphism in Swift (if not)
body: <p>I have this code in swift: To explain the idea of polymorphism! </p>
  
  <pre><code>//Polymorphism
  
  
  class Person {
  var name:String="Guest"
  var age:Int=0
  
  init(name:String) {
      self.name=name
      self.age=0
  }
  init(name:String, age:Int) {
      self.name=name
      self.age=age
  }
  
  func Update(name:String) {
      self.name=name
  }
  func Upgrade() {
      self.age++
  }
  }
  
  
  
  class Student:Person
  {
  var average:Float=100
  func IsOk()-&gt;Bool {
      return average &gt; 80
  }
  init(name:String, average:Float) {
      super.init(name: name)
      self.average=average
  }
  }
  
  
  class Teacher:Person {
  var Salary:Float=2000
  init(name:String, age:Int, Salary:Float){
      super.init(name: name, age: age)
      self.Salary=Salary
  
  }
  func GetNetSalary()-&gt;Float {
      return 0.8*self.Salary
  }
  
  override func Upgrade() {
      super.Upgrade()
      Salary*=1.1 // add 10% to salary
  }
  }
  
  
  
  var t1:Teacher=Teacher(name: "Ahmed", age: 28, Salary: 3000)
  var st1=Student(name:"Test", average: 70)
  
  var p1:Person=Person(name: "abc")
  var p2:Person=Student(name: "Student1", average: 100) //up casting
  var p3:Person=Teacher(name: "Teacher", age: 40, Salary: 3008)
  
  
  var arr=[t1, st1, p1, p2, p3] //array of persons and teachers and students
  
  for instance in arr {
  if instance is Student {println("This is student")}
  if instance is Teacher {println("This is teacehr")}  
  }
  </code></pre>
  
  <p>In the end in the for loop How could I put such a condition to see if an element in the array is only a Person? 
  Because when I type:</p>
  
  <pre><code>if instance is Person {println("This is a Person")}
  </code></pre>
  
  <p>This gives me an error because this condition is always true!</p>