Reputation: 397
I study how to make iOS app by codingforentrepreneurs.com
nowadays I study Alamofire. Xcode is 8.3.3
this is error command. I don't understand error command.
Cannot convert value of type '(NSURLRequest, HTTPURLResponse?, AnyObject?, NSError?) -> Void' to expected argument type '(DataResponse) -> Void'
this is ViewController.swift
import UIKit
import Alamofire
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var rTest = Alamofire.request("http://ec2-52-78-193-10.ap-northeast-2.compute.amazonaws.com", method: .get)
.responseJSON(completionHandler: isComplete)
}
func isComplete(request:NSURLRequest, response: HTTPURLResponse?, data: AnyObject?, error:NSError?) -> Void {
print(response!.statusCode)
print(data)
print(error)
print(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
i don't know what is problem. could you help me?
Upvotes: 1
Views: 879
Reputation: 33979
The error, in this case, correctly describes the problem.
The completion handler you passed in was of type (NSURLRequest, HTTPURLResponse?, AnyObject?, NSError?) -> Void
but that is not the correct type for an Alamofire completion handler. The correct type is (DataResponse) -> Void
This means you need to change your isComplete
method to something like:
func isComplete(dataResponse: DataResponse<Any>) -> Void {
print(dataResponse)
}
Upvotes: 0
Reputation: 19156
Signature of the completion handler method should be like this.
func isComplete(response: DataResponse<Any>) {
let statusCode = response?.response?.statusCode
let result = response?.result
let request = response?.request
}
Upvotes: 0