简体   繁体   English

Alamofire无法在当前上下文中推断闭包类型

[英]Alamofire Unable to infer closure type in the current context

I'm creating the extension for DataRequest to log events 我正在为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 */
            }
        }
}

and got the error Unable to infer closure type in the current context Since it has (DataResponse<T.SerializedObject>) -> Void generic type, is there a way to explicitly set the type to fix this error? 并得到错误Unable to infer closure type in the current context因为它具有(DataResponse<T.SerializedObject>) -> Void泛型类型,有没有办法显式设置该类型以解决此错误?

Alamofire version: 4.7.2 Xcode version: 9.3 Swift version: 4.0 Platform(s) running Alamofire: iOS Alamofire版本: 4.7.2 Xcode版本: 9.3 Swift版本: 4.0 运行Alamofire的平台: iOS

func log() -> Self {
        let responseSerializer = DataRequest.jsonResponseSerializer()
        return response(responseSerializer: responseSerializer) { [weak self] response in
            guard let _self = self else { return }
            _self.printRequestString(response)
        }
    }

Works well. 效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在当前上下文中推断闭包类型 - Unable to infer closure type in the current context 无法在SwiftUI的当前上下文中推断闭包类型 - Unable to infer closure type in the current context in SwiftUI Swift 3.0:无法推断当前上下文中的闭包类型PromiseKit - Swift 3.0: Unable to infer closure type in the current context ,PromiseKit 将文件转换为Swift 3:无法在当前上下文中推断闭包类型 - Converting a file to Swift 3: unable to infer closure type in the current context “无法在当前上下文中推断闭包参数 'b' 的类型”。 调用 function 时出现此错误 - "Unable to infer type of a closure parameter 'b' in the current context". Getting this error while calling the function Swift 无法推断复杂的闭包返回类型 - Swift unable to infer complex closure return type 无法推断出复杂的闭包返回类型; 添加显式类型以消除歧义 - Unable to infer complex closure return type; add explicit type to disambiguate 无法推断复杂的闭包返回类型 SwiftUI ForEach - Unable to infer complex closure return type SwiftUI ForEach Swift Combine:无法推断复杂的闭包返回类型错误 - Swift Combine: Unable to infer complex closure return type error SwiftUI:ForEach 无法推断复杂的闭包返回类型 - SwiftUI: ForEach Unable to infer complex closure return type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM