title: Get NSData from buffer in Swift
body: <p>I'm trying to get the image represented as buffer on this URL: <a href="http://apiapp-env2.elasticbeanstalk.com/?nomfile=FX1wTPcaZQ1456021964555.png" rel="nofollow">http://apiapp-env2.elasticbeanstalk.com/?nomfile=FX1wTPcaZQ1456021964555.png</a></p>
  
  <p>As you can see in the response, the image is a Buffer stored in the data object inside the JSON (I'm not the owner of the API, so I can't modify it)</p>
  
  <p>Well, I'm trying to convert the image from the buffer to a UIImage.
  This is what one of the things that I'have tried so far:</p>
  
  <pre><code>    Alamofire.request(.GET, URL, parameters: nil, encoding: .JSON)
    .validate()
    .response{
      request, response, json, error in
      if let _ = error{
        callback?(image: UIImage(named: "placeholder")!)
      }else if let _: AnyObject = json{
        do {
          let jsonObject = try NSJSONSerialization.JSONObjectWithData(json!, options:[])
          let bufferData = JSON(jsonObject)["Body"]["data"].array
          let imageData = NSData(bytes: bufferData!, length: bufferData!.count / sizeof(UInt32))
          let downloadImage = UIImage(data:imageData)
          callback?(image: downloadImage!)
        } catch {
          print("Error[performLoginSocialRequest]: \(error)")
        }
      }
  }
  </code></pre>
  
  <p>But the downloadImage object is always nil.
  Does anybody faced this issue before? If so, how can you solve it?</p>