I have installed Alamofire and SwiftyJSON with Cocoapods. Independently, each are working great. However when I try and mix the two I get an error.
Before using Alamofire I used NSURLConnection to download data. When the connectionHandler finished I created a JSON object with SwiftyJSON.
let json = JSON(data: self.downloadedData!)
This worked without any issues.
To make things cleaner I wanted to use Alamofire. When I use Alamofire I try to create a JSON object with SwiftyJSON.
Alamofire.request(.GET, "http://162.208.56.92/json_service.php").responseJSON()
{
(_, _, JSON, _) in
let json = JSON(data: JSON)
}
When I do this I get the following error.
Cannot invoke 'JSON' with an argument list of type '(data: AnyObject?)'
Since JSON takes an NSData argument I tried the following.
Alamofire.request(.GET, "http://162.208.56.92/json_service.php").responseJSON()
{
(_, _, JSON, _) in
let json = JSON(data: JSON as! NSData)
}
This gave me the following error.
Cannot invoke 'JSON' with an argument list of type '(data: NSData)'
I am stumped. Any thoughts?
You must encode the result using dataUsingEncoding. Try to convert your result using the code below: