I want to display my instagram on iOS app. I'm using Alamofire and Swifty libraries for JSON with this tutorial http://myxcode.net/2015/07/12/getting-data-from-instagram-account/
However I'm getting error in this line:
Alamofire.request(.GET, url).responseJSON { (request, response, json, error) in
saying "Void expects 1 argument but 4 were used in closure body".
But if I use
Alamofire.request(.GET, url)
.responseJSON { response in
print(response)
}
It prints the result correctly.
If i use
Alamofire.request(.GET, url)
.responseJSON { response in
let data = response["data"].arrayValue as [JSON]?
that I got from https://github.com/Alamofire/Alamofire I get error "Type 'Response' has no subscript members"
How can I use this?
As mentioned on the Almofire GitHub page you have to use following if you want to get 4 parameters directly
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.response { request, response, data, error in
print(request)
print(response)
print(data)
print(error)
}
You can't use 4 parameters with the responseJSON
as it only has one parameter as you have written in the example
but you can get 4 value from the response like this
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
You can get everything from the response object