Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

Commit

Permalink
Fix update instead of move (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
batjo authored and 3lvis committed Feb 19, 2018
1 parent 571bc88 commit 1bd2ebe
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Source/DATASource+NSFetchedResultsControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,24 @@ extension DATASource: NSFetchedResultsControllerDelegate {
break
case .move:
if let indexPath = indexPath, let newIndexPath = newIndexPath {
tableView.deleteRows(at: [indexPath], with: rowAnimationType)
tableView.insertRows(at: [newIndexPath], with: rowAnimationType)
// Workaround: Updating a UICollectionView element sometimes will trigger a .Move change
// where both indexPaths are the same, as a workaround if this happens, DATASource
// will treat this change as an .Update
if indexPath == newIndexPath {
if let cell = tableView.cellForRow(at: newIndexPath) {
self.configure(cell, indexPath: newIndexPath)
}

if let anObject = anObject as? NSManagedObject {
self.delegate?.dataSource?(self, didUpdateObject: anObject, atIndexPath: newIndexPath)
}
} else {
tableView.deleteRows(at: [indexPath], with: rowAnimationType)
tableView.insertRows(at: [newIndexPath], with: rowAnimationType)

if let anObject = anObject as? NSManagedObject {
self.delegate?.dataSource?(self, didMoveObject: anObject, fromIndexPath: indexPath, toIndexPath: newIndexPath)
if let anObject = anObject as? NSManagedObject {
self.delegate?.dataSource?(self, didMoveObject: anObject, fromIndexPath: indexPath, toIndexPath: newIndexPath)
}
}
}
break
Expand Down

0 comments on commit 1bd2ebe

Please sign in to comment.