问题
I imported Alamofire the way I used to successfully import it, and when I had this code, there comes an error:
Alamofire.request(.GET, postEndPoint).responseJSON {(request, response, result) in
//Error: '(_, _, _) -> Void' is not convertible to 'Response<AnyObject, NSError> -> Void'
guard let value = result.value else {
print("Error: did not receive data")
return
}
guard result.error == nil else {
print("error calling GET on /posts/1")
print(result.error)
return
}
let post = JSON(value)
print("The post is: " + post.description)
if let title = post["title"].String {
print("The title is: " + title)
} else {
print("Error parsing /posts/1")
}
}
I didn't use CocoaPods for Alamofire.
回答1:
See the Alamofire 3.0 Migration Guide.
Alamofire.request(.GET, postEndPoint).responseJSON { response in
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
This is the new way of getting the JSON.
response.result
is the new way of getting result
.
Alamofire.request(.GET, postEndPoint).responseJSON { response in
guard let value = response.result.value else {
print("Error: did not receive data")
return
}
guard response.result.error == nil else {
print("error calling GET on /posts/1")
print(response.result.error)
return
}
let post = JSON(value)
print("The post is: " + post.description)
if let title = post["title"].String {
print("The title is: " + title)
} else {
print("Error parsing /posts/1")
}
}
来源:https://stackoverflow.com/questions/32960808/void-is-not-convertible-to-responseanyobject-nserror-void