Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created August 12, 2016 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odrobnik/ef04514ed0c3f255d061f96fb4df36ef to your computer and use it in GitHub Desktop.
Save odrobnik/ef04514ed0c3f255d061f96fb4df36ef to your computer and use it in GitHub Desktop.
public extension CollectionType where Generator.Element == NSIndexPath
{
func indexPathsWithSectionModified(by modifier: Int) -> [NSIndexPath]
{
var modifiedIndexPaths = [NSIndexPath]()
for indexPath in self
{
let modifiedIndexPath = NSIndexPath(forItem: indexPath.item, inSection: indexPath.section + modifier)
modifiedIndexPaths.append(modifiedIndexPath)
}
return modifiedIndexPaths
}
func indexPathsWithItemModified(by modifier: Int) -> [NSIndexPath]
{
var modifiedIndexPaths = [NSIndexPath]()
for indexPath in self
{
let modifiedIndexPath = NSIndexPath(forItem: indexPath.item + modifier, inSection: indexPath.section)
modifiedIndexPaths.append(modifiedIndexPath)
}
return modifiedIndexPaths
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment