title: Swift downcasting fails
body: <p>I have encountered very weird behavior and I really can't make heads or tails of it. I am trying to store class types in the array and want to call later on but it doesn't work. Here is my code</p>
  
  <pre><code>class BaseClass {
  
      class func getDetails() -&gt; String {
          return "aaaaaa"
      }
  }
  
  class Foo: BaseClass {
  
      override class func getDetails() -&gt;String {
          return "foo"
      }
  }
  
  
  class Bar: BaseClass {
      override class func getDetails() -&gt;String {
          return "bar"
      }
  }
  
  var arr = [Foo.self, Bar.self]
  func test1 () {
  
      var x = Foo.self
      println(x.getDetails()) //prints foo
      if let y = arr[0] as? Foo.Type {
          println(y.getDetails()) //doesn't execute
  
      }
      if let z = arr[0] as? BaseClass.Type {
          println(z.getDetails()) //doesn't execute
      }
      if let t = arr[0] as? BaseClass {
          println(t.dynamicType.getDetails()) //doesn't execute
      }
      // lets crash
      var w = arr[0] as! Foo
      //Could not cast value of type 'Test.Foo' (0x1085f17f0) to 'Test.Foo' (0x1085f1830).
  
  }
  </code></pre>
  
  <p>I am especially puzzled by </p>
  
  <blockquote>
    <p>Could not cast value of type 'Test.Foo' (0x1085f17f0) to 'Test.Foo'
    (0x1085f1830)</p>
  </blockquote>
  
  <p>error. How can I refer to classes in the array by downcasting to <code>BaseClass</code> to that I can use its <code>getDetails</code> function</p>