1
Array(またはSequenceまたはCollector?)の拡張を定義して、NSIndexPathを使用してカスタムオブジェクトのリストを照会し、indexPathのセクションに基づいてオブジェクトを取得できるようにしたいと行。配列内の配列のSwift汎用拡張子
public var tableViewData = [[MyCellData]]() // Populated elsewhere
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var tableViewCellData = tableViewData.data(from: indexPath)
// use tableViewCellData
}
// This does not compile as I want the return type to be that of which is the type "in the list in the list" (i.e. MyCellData)
extension Sequence<T> where Iterator.Element:Sequence, Iterator.Element.Element:T {
func object(from indexPath: NSIndexPath) -> T {
return self[indexPath.section][indexPath.row]
}
}
感謝を!まさに私が探していたもの! – Sunkas