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
}
}
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) }
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.