title: Server Authentication in Swift 2.0 & XCode 7 broken
body: <p>I just updated my code to Swift 2.0 to work with Xcode 7. My App performs <code>NSURLAuthenticationMethodServerTrust</code> and <code>NSURLAuthenticationMethodClientCertificate</code> authentication.</p>
  
  <p>The problem is <code>NSURLAuthenticationMethodServerTrust</code> authentication stopped working on my simulator - but still works on my test device with iOS 8.3. Besides my old project which is not Swift 2.0, is also still working.</p>
  
  <p>Error: <code>NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)</code></p>
  
  <p>Error retrieved from NSURLSession: </p>
  
  <pre><code>Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x7fcf75053070 {NSURLErrorFailingURLPeerTrustErrorKey=&lt;SecTrustRef: 0x7fcf73700d00&gt;, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9802, NSUnderlyingError=0x7fcf735284b0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1200.)", NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://mywebapi/dosomething, NSErrorFailingURLStringKey=https://mywebapi/dosomething, _kCFStreamErrorDomainKey=3} [GetOneTimeTokenController.swift:76]
  </code></pre>
  
  <p>I am still targeting iOS 8.0 for deployment.</p>
  
  <p>This is how I handle the Authentication Challenge (using a self signed certificate):</p>
  
  <pre><code>if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate {
  
          let urlCredential:NSURLCredential = NSURLCredential(
              identity: identityAndTrust.identityRef,
              certificates: identityAndTrust.certArray as [AnyObject],
              persistence: NSURLCredentialPersistence.ForSession);
  
          completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, urlCredential);
  
      } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {
  
          completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, NSURLCredential(trust: challenge.protectionSpace.serverTrust!));
  
      } else {
  
          challenge.sender?.continueWithoutCredentialForAuthenticationChallenge(challenge)
          Logger.sharedInstance.logMessage("Unexpected Authentication Challange", .Error);
  
      }
  </code></pre>