加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 无法转换’T’类型的值?预期的参数类型’_?’ – 通

发布时间:2020-12-14 02:28:38 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Alamofire 3和最新版本的ObjectMapper( https://github.com/Hearst-DD/ObjectMapper)实现AlamofireObjectMapper( https://github.com/tristanhimmelman/AlamofireObjectMapper). 似乎AlamofireObjectMapper尚未更新与Alamofire 3一起使用,所以
我正在尝试使用Alamofire 3和最新版本的ObjectMapper( https://github.com/Hearst-DD/ObjectMapper)实现AlamofireObjectMapper( https://github.com/tristanhimmelman/AlamofireObjectMapper).

似乎AlamofireObjectMapper尚未更新与Alamofire 3一起使用,所以我正在尝试自己做.

我来到这段代码,现在我被卡住了.

似乎通用类型T在响应的完成块内是不可访问的.是Alamofire 3改变还是Swift 2.1改变?

这是错误:

Cannot convert value of type ‘T?’ to expected argument type ‘_?’

public func responSEObject<T: Mappable>(queue: dispatch_queue_t?,keyPath: String?,completionHandler: (NSURLRequest,NSHTTPURLResponse?,T?,AnyObject?,ErrorType?) -> Void) -> Self {
    return response(queue: queue) { (request,response,data,error) -> Void in
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0)) {
            let JSONResponseSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
            let result = JSONResponseSerializer.serializeResponse(request,error)
            let parsedObject = Mapper<T>().map(keyPath != nil ? result.value?[keyPath!] : result.value)

            dispatch_async(queue ?? dispatch_get_main_queue()) {
                completionHandler(self.request!,self.response,parsedObject,result.value ?? response.data,result.error) // Here it shows the error: Cannot convert value of type 'T?' to expected argument type '_?' 
            }
        }
    }

}
刚刚找到解决方案.
这似乎是Xcode 7.1 beta编译器的一个问题.它在“parsedObject”参数上给出了问题,并且下一个参数出错了.
completionHandler(self.request!,**result.value ?? data**,result.error)

因此,如果您碰巧遇到相同的错误,请查看所有其他参数是否正常.

祝好运.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读