(_, _, _) & # 8594; Void 'does not convert to' Response <AnyObject, NSError> & # 8594; Void '

I imported Alamofire the way I imported it successfully, and when I got this code, an error occurs:

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 have not used CocoaPods for Alamofire.

0
xcode swift alamofire
Oct 06 '15 at 2:30
source share
1 answer

See Alamofire 3.0 Migration Guide .

 Alamofire.request(.GET, postEndPoint).responseJSON { response in if let JSON = response.result.value { print("JSON: \(JSON)") } } 

This is a new way to get JSON.




response.result is a new way to get 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") } } 
+4
Oct 06 '15 at 2:35
source share



All Articles