title: How do you find out the type of an object (in Swift)?
body: <p>When trying to understand a program, or in some corner-cases, it's useful to find out what type something is. I know the debugger can show you some type information, and you can usually rely on type inference to get away with not specifying the type in those situations, but still, I'd really like to have something like Python's <code>type()</code></p>
  <h2>dynamicType (see <a href="https://stackoverflow.com/questions/24049487/how-do-you-retrieve-the-type-of-an-object-in-swift">this question</a>)</h2>
  <p><strong>Update:</strong> this has been changed in a recent version of Swift, <code>obj.dynamicType</code> now gives you a reference to the type and not the instance of the dynamic type.</p>
  <p>This one seems the most promising, but I haven't been able to find out the actual type so far.</p>
  <pre><code>class MyClass {
      var count = 0
  }
  
  let mc = MyClass()
  
  # update: this now evaluates as true
  mc.dynamicType === MyClass.self
  </code></pre>
  <p>I also tried using a class reference to instantiate a new object, which <em>does</em> work, but oddly gave me an error saying I must add a <code>required</code> initializer:</p>
  <p>works:</p>
  <pre><code>class MyClass {
      var count = 0
      required init() {
      }
  }
  
  let myClass2 = MyClass.self
  let mc2 = MyClass2()
  </code></pre>
  <p>Still only a small step toward actually discovering the type of any given object though</p>
  <p><strong>edit</strong>: I've removed a substantial number of now irrelevant details - look at the edit history if you're interested :)</p>