【发布时间】:2016-01-07 12:20:55
【问题描述】:
我正在尝试详细了解
.drive(resultsTableView.rx_itemsWithCellIdentifier("WikipediaSearchCell",
cellType: WikipediaSearchCell.self))
{ (_, viewModel, cell) in
cell.viewModel = viewModel
}
来自 WikipediaSearchViewController.swift 第 47-64 行。 我试图提取参数以查看具体的类型签名,但重写为
let temp1 = searchBar.rx_text
.asDriver()
.throttle(0.3)
.distinctUntilChanged()
.flatMapLatest { query in
API.getSearchResults(query)
.retry(3)
.retryOnBecomesReachable([], reachabilityService: ReachabilityService.sharedReachabilityService)
.startWith([]) // clears results on new search term
.asDriver(onErrorJustReturn: [])
}
.map { results in
results.map(SearchResultViewModel.init)
}
let driveArg1 = resultsTableView.rx_itemsWithCellIdentifier("WikipediaSearchCell", cellType: WikipediaSearchCell.self)
let driveArg2 = { (_, viewModel: SearchResultViewModel, cell: WikipediaSearchCell) in
cell.viewModel = viewModel
}
temp1.drive(driveArg1, curriedArgument: driveArg2)
.addDisposableTo(disposeBag)
给了
无法使用“(String, cellType: UITableViewCell.Type)”类型的参数列表调用“rx_itemsWithCellIdentifier”
对于 driveArg1 和
没有更多上下文,表达式的类型是模棱两可的
对于 driveArg2。
drive和rx_itemsWithCellIdentifier的签名是
public func drive<R1, R2>(with: Self -> R1 -> R2, curriedArgument: R1) -> R2 {}
public func rx_itemsWithCellIdentifier(cellIdentifier: String, cellType: Cell.Type = Cell.self)(source: O)(configureCell: (Int, S.Generator.Element, Cell) -> Void) -> Disposable {}
但在这一点上 Swift 语法对我来说是不可理解的。谁能解释一下签名和代码中发生了什么?
【问题讨论】:
-
我了解到存在某种泛型类型不匹配。并且在 rx_itemsWithCellIdentifier 函数参数中无法确定 (S: SequenceType) 的泛型类型。