I have custom CollectionView
cell and on button tap I am calling closure
which is implemented under cellForItem
below is code
cell.closeImageTappped = { [weak self] cell in
guard let strongSelf = self else {
return
}
if let objectFirst = strongSelf.selectedFiles.first(where: {$0.fileCategory == cell.currentSelectedCellType && $0.fileName == cell.currentObject?.fileName}) {
cell.imgPicture.image = nil
cell.imgPlusPlaceHolder.isHidden = false
objectFirst.removeImageFromDocumentDirectory()
strongSelf.selectedFiles.remove(at: strongSelf.selectedFiles.index(where: {$0.fileName == objectFirst.fileName})!)
strongSelf.arraySource[indexPath.section].rows.remove(at: indexPath.row)
strongSelf.collectionViewSelectFile.performBatchUpdates({
strongSelf.collectionViewSelectFile.deleteItems(at: [indexPath])
}, completion: nil)
}
}
App Crashes in some cases like if I am pressing close multiple cells too fast
Crash here
strongSelf.arraySource[indexPath.section].rows.remove(at: indexPath.row)
fatal error: Index out of range
When I check rows
▿ 11 elements - 0 : 0 - 1 : 1 - 2 : 2 - 3 : 3 - 4 : 4 - 5 : 5 - 6 : 6 - 7 : 7 - 8 : 8 - 9 : 8 - 10 : 8
While IndexPath is
po indexPath
▿ 2 elements
- 0 : 0
- 1 : 11
If I get indexPath like this it shows me correct IndexPath
self?.collectionViewSelectFile.indexPath(for: cell)
▿ Optional<IndexPath>
▿ some : 2 elements
- 0 : 0
- 1 : 9
But Why IndexPath
is different then self?.collectionViewSelectFile.indexPath(for: cell)