使用
Xcode 7.1
使用了 Github的AlamofireObjectMapper框架.我无法使用responSEObject处理程序.
使用了 Github的AlamofireObjectMapper框架.我无法使用responSEObject处理程序.
以下是代码:
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) }
即使我删除’ – > Void’从代码中没有区别. WeatherResponse是一个自定义类,包含以下代码:
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"] } }
错误:
解决方法
responSEObject的方法签名是
public func responSEObject<T: Mappable>(completionHandler: (T?,ErrorType?) -> Void) -> Self
请注意,error参数是ErrorType?,而不是NSError?.调用闭包的正确方法是:
Alamofire.request(.GET,url).responSEObject{(response: WeatherResponse?,error: ErrorType?) -> Void in print(response?.location) }
一定要导入Alamofire,AlamofireObjectMapper和ObjectMapper.