title: Swift type casting issue
body: <p>I have a weird crash (like 1 for 10 000 times), here is a code:</p>
  
  <pre><code>typealias APIData = Dictionary &lt;String, AnyObject&gt;
  
  static func performAction(action: APIAction, params: APIParams, needAuthorization: Bool = true, completion: APICompletion) -&gt; AFHTTPRequestOperation? {
      var requestParameters: APIParams = ["request": params]
  
      if needAuthorization &amp;&amp; sessionIsValid() {
          requestParameters["session_id"] = sessionID!
      }
  
      APILogger.logAction(action, params: requestParameters)
  
      return API.requestManager.POST(action.rawValue, parameters: requestParameters, success: { (operation, data) -&gt; Void in
  
          guard let _data = data as? APIData, errorCode = _data["errorCode"] as? Int, error = APIError(rawValue: errorCode) else {
              completion(state: .Failed, data: nil, error: .Undefined)
              return
          }
  
          if error == .NoError {
              if let responceData = _data["response"] as? APIData {
                  APILogger.logData(_data)
                  completion(state: .Success, data: responceData, error: error)
              } else {
                  completion(state: .Success, data: nil, error: error)
              }
          } else {
              if error == .ExpiredSession {
                  sessionID = nil
              }
              completion(state: .Failed, data: nil, error: error)
          }
  
          }) { (operation, error) -&gt; Void in
              if operation.cancelled {
                  completion(state: .Cancelled, data: nil, error: .Undefined)
              } else {
                  completion(state: .Failed, data: nil, error: .Undefined)
              }
      }
  }
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>                Thread : Crashed: com.apple.main-thread
              0  libswiftCore.dylib             0x0000000100645cbc swift::_swift_getClass(void const*) + 24
              1  libswiftCore.dylib             0x000000010063d57c swift_getObjectType + 12
              2  libswiftCore.dylib             0x000000010062209c _dynamicCastFromExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::ExistentialTypeMetadata const*, swift::Metadata const*, swift::DynamicCastFlags) + 156
              3  libswiftCore.dylib             0x0000000100620e2c swift_dynamicCast + 496
              4  BenefitCalculator_iOS          0x000000010012a2ec static API.(performAction(API.Type) -&gt; (APIAction, params : [String : AnyObject], needAuthorization : Bool, completion : (state : APIOperationState, data : [String : AnyObject]?, error : APIError) -&gt; ()) -&gt; AFHTTPRequestOperation?).(closure #1) (API.swift:43)
              5  BenefitCalculator_iOS          0x000000010012aa28 thunk (API.swift)
              6  BenefitCalculator_iOS          0x000000010012aa54 thunk (API.swift)
              7  BenefitCalculator_iOS          0x000000010012aab4 thunk (API.swift)
              8  libdispatch.dylib              0x0000000196fb1994 _dispatch_call_block_and_release + 24
              9  libdispatch.dylib              0x0000000196fb1954 _dispatch_client_callout + 16
              10 libdispatch.dylib              0x0000000196fb620c _dispatch_main_queue_callback_4CF + 1608
              11 CoreFoundation                 0x00000001850f37f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
              12 CoreFoundation                 0x00000001850f18a0 __CFRunLoopRun + 1492
              13 CoreFoundation                 0x000000018501d2d4 CFRunLoopRunSpecific + 396
              14 GraphicsServices               0x000000018e8336fc GSEventRunModal + 168
              15 UIKit                          0x0000000189be2fac UIApplicationMain + 1488
              16 BenefitCalculator_iOS          0x0000000100122f4c main (AppDelegate.swift:15)
              17 libdyld.dylib                  0x0000000196fdea08 start + 4
  </code></pre>
  
  <p>According to stack trace it's crashing here:</p>
  
  <pre><code>guard let _data = data as? APIData, errorCode = _data["errorCode"] as? Int, error = APIError(rawValue: errorCode) else
  </code></pre>
  
  <p>It's so hard to recreate this crash...</p>
  
  <p>It's seems Swift type casting could crash even if I do it right (let _data = data as? APIData) and it's very rare. I would be very appreciated if someone could help me to solve this.</p>