title: Typecasting in Swift
body: <p>I am writing a library which can parse typed Ids from JSON. However, I am finding the typecasting rules a little baffling.</p>
  
  <p>Example:</p>
  
  <pre class="lang-swift prettyprint-override"><code>class AccountId : NSString { }
  
  let json : AnyObject? = "user-1" // Returned by NSJSONSerialization.JSONObjectWithData
  let s = json as? NSString   // Succeeds, s == Some("user-1")
  let a = json as? AccountId  // Fails, a == nil
  </code></pre>
  
  <p>Why does the first typecast succeed while the second one fail? Is there something magical about <code>NSString</code> which does not crossover to Swift-only classes?</p>
  
  <p>I am using XCode Version 6.1 (6A1030) (the latest at the time of writing).</p>