@@ -82,9 +82,9 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
8282 public func apply( _ sections: [ SPDiffableSection ] , animated: Bool ) {
8383 if #available( iOS 14 , * ) {
8484
85- var snapshot = self . snapshot ( )
85+ // Remove section if it deleted from content.
8686
87- // Remove section if it deleted from content
87+ var snapshot = self . snapshot ( )
8888
8989 let deletedSections = snapshot. sectionIdentifiers. filter ( { ( checkSection) -> Bool in
9090 return !sections. contains ( where: { $0. identifier == checkSection. identifier } )
@@ -94,7 +94,7 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
9494 apply ( snapshot, animated: true )
9595 }
9696
97- // Reoder sections
97+ // Reoder
9898
9999 for (sectionIndex, section) in sections. enumerated ( ) {
100100 let previousSectionIndex = sectionIndex - 1
@@ -105,7 +105,11 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
105105 snapshot. moveSection ( section, afterSection: previousSection)
106106 }
107107
108- // Add new sections and update current sections
108+ // Apply Sections Changes
109+
110+ apply ( snapshot, animated: true )
111+
112+ // Update current sections.
109113
110114 for section in sections {
111115 var sectionSnapshot = SPDiffableSectionSnapshot ( )
@@ -123,11 +127,6 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
123127 sectionSnapshot. expand ( sectionSnapshot. items)
124128 apply ( sectionSnapshot, to: section, animatingDifferences: animated)
125129 }
126-
127- // Apply changes
128-
129- apply ( snapshot, animated: true )
130-
131130 } else {
132131 var snapshot = SPDiffableSnapshot ( )
133132 snapshot. appendSections ( sections)
0 commit comments