Reputation: 6554
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
}
}
Upvotes: 4
Views: 2347
Reputation: 539795
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) }
}
}
Upvotes: 5