title: NSDictionary to NSData and NSData to NSDictionary in Swift
body: <p>I am not sure if I am using the dictionary or the data object or both incorrectly. I m trying to get used to the switch to swift but I'm having a little trouble.</p>
  
  <pre><code>var dictionaryExample : [String:AnyObject] =
      ["user":"UserName",
       "pass":"password",
      "token":"0123456789",
      "image":0] // image should be either NSData or empty
  
  let dataExample : NSData = dictionaryExample as NSData
  </code></pre>
  
  <p>I need the <code>NSDictionary</code> to encode to an <code>NSData</code> object as well as taking that <code>NSData</code> object and decode it into a <code>NSDictionary</code>.</p>
  
  <p>Any help is greatly appreciated, thanks.</p>