使用RxSwift Observable.zip时上下文封闭类型'(_,_)-> _'预期会出现2个参数错误

时间:2018-10-24 13:48:57

标签: rx-swift

如何在构建下面的代码时解决以下构建错误:

  

上下文关闭类型'(_,_)-> _'需要2个参数,但1个是   用于闭包正文插入',<#arg#>'

代码

func getIncidentAndResolutionTree() -> Observable<([Incident],[Resolution])>
{
    return Observable.zip(getIncidents(), getResolutionTree(), resultSelector: { results  -> ([Incident], [Resolution]) in
        return results
    })
}

配置

Xcode 9.4.1,Swift 4.1 RxSwift 4.3.1

1 个答案:

答案 0 :(得分:0)

Lambda需要2个参数,而不仅仅是results

这将编译-

return Observable.zip(getIncidents(), getResolutionTree(), resultSelector: { (incidents, resolutions)  -> ([Incident], [Resolution]) in
  return (incidents, resolutions)
})

尽管那样会更优雅-

return Observable.zip(getIncidents(), getResolutionTree()) { ($0, $1) }