Swift 3.0:“IndexSet”类型的值没有成员“enumerateIndexesUsingBlock”

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)

Mar*_*n R 5

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)