我正在为记录事件的DataRequest创建扩展
func log() -> Self {
let responseSerializer = DataRequest.jsonResponseSerializer(options: .allowFragments)
return response(queue: nil, responseSerializer: responseSerializer) { response in
if let object = response.result.value {
/* do the job */
}
}
}
得到了误差
Unable to infer closure type in the current context
由于它具有
(DataResponse<T.SerializedObject>) -> Void
泛型类型,是否有方法显式设置该类型以修复此错误?阿拉莫菲尔版本:
4.7.2条
Xcode版本:
九点三
Swift版本:
四
运行Alamofire的平台:
网间网操作系统
最佳答案
func log() -> Self {
let responseSerializer = DataRequest.jsonResponseSerializer()
return response(responseSerializer: responseSerializer) { [weak self] response in
guard let _self = self else { return }
_self.printRequestString(response)
}
}
效果很好。
关于ios - Alamofire无法在当前上下文中推断闭包类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50583101/