title: How to Connect localhost (with invalid certificate) using Alamofire?
body: <p>This my first project using swift. I am usin alamofire to connect the API. I have a local copy form the API I want to use for debugging - so I can set test data - because the remote API has already real data that I can't mess with.</p>
  
  <p>The problem is I am getting the below error when I try to access <code>https://localhost:8443/MyProject</code></p>
  
  <blockquote>
    <p>Optional(Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost” which could put your confidential information at risk." UserInfo=0x7fbeb8c61ff0 {NSURLErrorFailingURLPeerTrustErrorKey=, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9813, NSUnderlyingError=0x7fbeb8ea5c00 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1202.)", NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost” which could put your confidential information at risk., NSErrorFailingURLKey=<a href="https://localhost:8443/myproject/api/loginUser.pdo">https://localhost:8443/myproject/api/loginUser.pdo</a>, NSErrorFailingURLStringKey=<a href="https://localhost:8443/myproject/api/loginUser.pdo">https://localhost:8443/myproject/api/loginUser.pdo</a>, _kCFStreamErrorDomainKey=3})</p>
  </blockquote>
  
  <p>I have found many solution most of them for Objective-c as using <code>setAllowsAnyHTTPSCertificate</code> or using the delegate for Connection.
  but I could not find an equevelent method for <code>setAllowsAnyHTTPSCertificate</code> in swift, and I not sure how to set the delegate to the connection while using alamofire.
  any ideas what I need to do?</p>
  
  <ul>
  <li>I know that <code>setAllowsAnyHTTPSCertificate</code> is private api and will cause the project to be rejected by Apple. I want to use it only while debugging then it will be removed before the publishing the project.</li>
  </ul>
  
  <p>Thank you in advance.</p>