Kir*_*nee 4 iphone ios swift swift3
Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock'在 enumerateIndexesUsingBlock接收错误。
/**
Extension for creating index paths from an index set
*/
extension IndexSet {
/**
- parameter section: The section for the created NSIndexPaths
- return: An array with NSIndexPaths
*/
func bs_indexPathsForSection(_ section: Int) -> [IndexPath] {
var indexPaths: [IndexPath] = []
self.enumerateIndexesUsingBlock { (index:Int, _) in
indexPaths.append(IndexPath(item: index, section: section));
}
return indexPaths
}
}
Run Code Online (Sandbox Code Playgroud)
Foundation 类型NSIndexSet有一个enumerateIndexesUsingBlock
方法。IndexSetSwift 3对应的覆盖类型是一个集合,因此你可以将每个索引映射到一个IndexPath:
extension IndexSet {
func bs_indexPathsForSection(_ section: Int) -> [IndexPath] {
return self.map { IndexPath(item: $0, section: section) }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2179 次 |
| 最近记录: |