title: Swift encoding/decoding images for JSON
body: <p>I'm kinda new to swift and i need some help with encoding some image, putting it in a JSON and after retrieving it, decoding it back to NSData and recreating the image in an UIImage view controller.
  I've found this post <a href="https://stackoverflow.com/questions/11251340/convert-image-to-base64-string-in-ios-swift/11251478#11251478">Convert Image to Base64 string in iOS + Swift</a> but i get stuck with this part:</p>
  
  <p><code>let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions.fromRaw(0)!)</code></p>
  
  <p>because the fromRaw method is not available anymore.</p>
  
  <p>Thanks in advance</p>
  
  <p>Later edit:
  I'm using swiftyJson to parse the array and i'm getting the image data like this:</p>
  
  <pre><code>var base64String = arrayJson[0]["photo"].stringValue
  var imageString = base64String as NSString
  </code></pre>
  
  <p>and after that i'm trying to decode it like this:</p>
  
  <pre><code>let decodedData = NSData(base64EncodedString: imageString, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)
  </code></pre>
  
  <p>I've also tried with the rawValue instead of IgnoreUnknownCharacters. Both return nil. Also tried with the base64String instead of imageString. Same thing.</p>