According to the docs, this should be as easy as this:
let newIndexPath = indexPath.dropFirst(1). //This is not working though.
What I have is a very complicated tableview ( I need to make my changes in cellForRow, anything else would require too large of a refactor, not to mention it wouldn't be very safe.)
Several sections - the section I am working on right now has different custom cells. I handle all the difference cells with an an enum. For the case I am working on right now, my data source (extensive and impossible to refactor right now) only accounts for this type of cell (not all the others in the section). of course I tried
[indexPath.row - 1]//And this works!! But is is not gonna fly in code review to add this as an index path to all my methods to configure this group of cells.
How can I start the indexPath over again in the same section? so my new group of cells can respond to the indexPath of the data source and all other methods.
I was thinking that indexPath.dropFirst(1) seemed ideal, but it is not working. I an Exec - unwrapping a value found to be nil error.
If you want the indexPath
to move back by 1
, use the .row
and .section
properties get the components and then use the IndexPath(row:section:)
initializer to create the newIndexPath
:
let newIndexPath = IndexPath(row: indexPath.row - 1, section: indexPath.section)