Swift 3.0: Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock'

倾然丶 夕夏残阳落幕 提交于 2020-06-23 07:13:43

问题


Receiving Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock' error at 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
    }
}

回答1:


The Foundation type NSIndexSet has a enumerateIndexesUsingBlock method. The corresponding overlay type IndexSet from Swift 3 is a collection, therefore you can just map each index to an IndexPath:

extension IndexSet {
    func bs_indexPathsForSection(_ section: Int) -> [IndexPath] {
        return self.map { IndexPath(item: $0, section: section) }
    }
}


来源:https://stackoverflow.com/questions/39638538/swift-3-0-value-of-type-indexset-has-no-member-enumerateindexesusingblock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!