@@ -45,7 +45,7 @@ open class FetchedResultsDataProvider<Object: NSFetchRequestResult>: NSObject, N
4545 configure ( fetchedResultsController)
4646
4747 try fetchedResultsController. performFetch ( )
48- dataProviderDidChangeContets ( with: nil )
48+ dataProviderDidChangeContents ( with: nil )
4949 }
5050
5151 public func object( at indexPath: IndexPath ) -> Object {
@@ -102,18 +102,31 @@ open class FetchedResultsDataProvider<Object: NSFetchRequestResult>: NSObject, N
102102 }
103103
104104 public func controllerDidChangeContent( _ controller: NSFetchedResultsController < NSFetchRequestResult > ) {
105- dataProviderDidChangeContets ( with: updates)
106- let updatesByMoves = updates. map ( { ( operation: DataProviderUpdate < Object > ) -> DataProviderUpdate < Object > ? in
105+ let updatesIndexPaths = updates. flatMap { update -> IndexPath ? in
106+ switch update {
107+ case . update( let indexPath, _) :
108+ return indexPath
109+ default : return nil
110+ }
111+ }
112+ updates = updates. flatMap { update -> DataProviderUpdate < Object > ? in
113+ if case . move( _, let newIndexPath) = update, updatesIndexPaths. contains ( newIndexPath) {
114+ return nil
115+ }
116+ return update
117+ }
118+ dataProviderDidChangeContents ( with: updates)
119+ let updatesByMoves = updates. flatMap { operation -> DataProviderUpdate < Object > ? in
107120 if case . move( _, let newIndexPath) = operation {
108121 return . update( newIndexPath, object ( at: newIndexPath) )
109122 }
110123 return nil
111- } ) . flatMap { $0 }
112- dataProviderDidChangeContets ( with: updatesByMoves)
124+ }
125+ dataProviderDidChangeContents ( with: updatesByMoves)
113126 }
114127
115- func dataProviderDidChangeContets ( with updates: [ DataProviderUpdate < Object > ] ? , triggerdByTableView : Bool = false ) {
116- if !triggerdByTableView {
128+ func dataProviderDidChangeContents ( with updates: [ DataProviderUpdate < Object > ] ? = nil , triggeredByTableView : Bool = false ) {
129+ if !triggeredByTableView {
117130 whenDataProviderChanged ? ( updates)
118131 }
119132 dataProviderDidUpdate ? ( updates)
0 commit comments