Bright
Bright

Reputation: 5741

(_, _, _) -> Void' is not convertible to 'Response<AnyObject, NSError> -> Void'

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.

Upvotes: 0

Views: 2279

Answers (1)

Jeffery Thomas
Jeffery Thomas

Reputation: 42588

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")
    }
}

Upvotes: 4

Related Questions