Cannot call "responseObject" with an argument list of type (("WeatherResponse ?, NSError?") & # 8594; Void

Using Xcode 7.1 Using the AlamofireObjectMapper framework from Github . I cannot use the responseObject handler.

Below is the code:

let url = "https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/f583be1121dbc5e9b0381b3017718a70c31054f7/sample_json"
    Alamofire.request(.GET, url).responseObject{(response :WeatherResponse?, error: NSError?) -> Void in
       print(response?.location)
        }

EVen, if I remove '-> Void' from the code, there is no difference. WeatherResponse is a custom class with the following code:

class WeatherResponse: Mappable {
var location: String?
var threeDayForecast: [Forecast]?

required init?(_ map: Map){

}

func mapping(map: Map) {
    location <- map["location"]
    threeDayForecast <- map["three_day_forecast"]
}
}

Mistake:

enter image description here

+4
source share
3 answers

Method signature for responseObjectequals

public func responseObject<T: Mappable>(completionHandler: (T?, ErrorType?) -> Void) -> Self

note that the error parameter is - ErrorType?and not NSError?. The correct way to call a closure is:

Alamofire.request(.GET, url).responseObject{(response: WeatherResponse?, error: ErrorType?) -> Void in
   print(response?.location)
}

Alamofire, AlamofireObjectMapper ObjectMapper.

0

AlamofireObjectMapper ObjectMapper

0

Currently with version 2.1 you can use:

Alamofire.request(.GET, URL, parameters: nil)
    .responseObject({ (response: Response< WeatherResponse, NSError>) -> Void in
        if response.result.isSuccess {
            print(response.result.value)
        }
    })

Good luck

0
source

Source: https://habr.com/ru/post/1607074/


All Articles