title: How to get cookie from a NSURLSession with Swift?
body: <p>I have a NSURLSession that calls dataTaskWithRequest in order to send a POST request in this way</p>
  
  <pre><code>func makeRequest(parameters: String, url:String){
      var postData:NSData = parameters.dataUsingEncoding(NSASCIIStringEncoding)!
      var postLength:NSString = String(postData.length )
      var request = NSMutableURLRequest(URL: NSURL(string: url)!)
      var session = NSURLSession.sharedSession()
      request.HTTPMethod = "POST"
  
      var error:NSError?
      //request.HTTPBody = NSJSONSerialization.dataWithJSONObject(postData, options: nil, error: &amp;error)
      request.HTTPBody = postData
      request.setValue(postLength, forHTTPHeaderField: "Content-Length")
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
      request.setValue("application/json", forHTTPHeaderField: "Accept")
  
      var task = session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -&gt; Void in
  
          println("Response:\(response)")
  
          // Other stuff goes here
  
  })
  </code></pre>
  
  <p>response is equal to: </p>
  
  <pre><code>&lt;NSHTTPURLResponse: 0x7fcd205d0a00&gt; { URL: http://XXX.XXX.XXX:0000/*** } { status code: 200, headers {
      "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
      Connection = close;
      "Content-Length" = 16;
      "Content-Type" = "application/json; charset=utf-8";
      Date = "Mon, 13 Apr 2015 00:07:29 GMT";
      Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
      Pragma = "no-cache";
      Server = "Apache/2.2.15 (CentOS)";
      "Set-Cookie" = "MYCOOKIEIS=12dsada342fdshsve4lorewcwd234; path=/";
      "X-Powered-By" = "PHP/5.3.14 ZendServer/5.0";
  } }
  </code></pre>
  
  <p>My problem here is that I don't know how to get the cookie that is there in "Set-Cookie" with name MYCOOKIEIS.</p>
  
  <p>I'll use this when user Login so If user is not logged in -> Login (call login api) Else Go to home screen and call other APIs.</p>
  
  <p>Somebody can help me to get the cookie out of there?</p>
  
  <p>I found this <a href="https://stackoverflow.com/a/24630935/2091181">answer</a> but it is in Objective-C and I don't know how to do it with Swift </p>