title: UIWebView: Save cookie state across app restarts
body: <p>I developing an application with Swift and an UIWebView that opens a webapp.
  Each time our users open the app, they need to login again because the app is not storing cookies. How can i solve it?</p>
  
  <p>I tried this to store cookies:</p>
  
  <pre><code>func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -&gt; Bool {
  
      println(request.URL!.absoluteString)
  
  
      var cookiesData = NSKeyedArchiver.archivedDataWithRootObject(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies!)
  
      NSUserDefaults.standardUserDefaults().setObject(cookiesData, forKey: "savedCookies")
  
      return true
  }
  </code></pre>
  
  <p>And to retrieve cookies again:</p>
  
  <pre><code>NSHTTPCookieStorage.sharedHTTPCookieStorage().cookieAcceptPolicy = NSHTTPCookieAcceptPolicy.Always
  let cookies = NSKeyedUnarchiver.unarchiveObjectWithData(NSUserDefaults.standardUserDefaults().objectForKey("cookies"))
  </code></pre>
  
  <p>I don't know how can i retrieve cookies in an array and iterate them.</p>