@@ -94,6 +94,17 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
94
94
apply ( snapshot, animated: true )
95
95
}
96
96
97
+ // Reoder sections
98
+
99
+ for (sectionIndex, section) in sections. enumerated ( ) {
100
+ let previousSectionIndex = sectionIndex - 1
101
+ guard ( sections. count > previousSectionIndex) && ( previousSectionIndex >= 0 ) else { continue }
102
+ let previousSection = sections [ previousSectionIndex]
103
+ guard let _ = snapshot. sectionIdentifiers. first ( where: { $0. identifier == section. identifier } ) else { continue }
104
+ guard let _ = snapshot. sectionIdentifiers. first ( where: { $0. identifier == previousSection. identifier } ) else { continue }
105
+ snapshot. moveSection ( section, afterSection: previousSection)
106
+ }
107
+
97
108
// Add new sections and update current sections
98
109
99
110
for section in sections {
@@ -113,17 +124,6 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
113
124
apply ( sectionSnapshot, to: section, animatingDifferences: animated)
114
125
}
115
126
116
- // Reoder sections
117
-
118
- for (sectionIndex, section) in sections. enumerated ( ) {
119
- let previousSectionIndex = sectionIndex - 1
120
- guard ( sections. count > previousSectionIndex) && ( previousSectionIndex >= 0 ) else { continue }
121
- let previousSection = sections [ previousSectionIndex]
122
- guard let _ = snapshot. sectionIdentifiers. first ( where: { $0. identifier == section. identifier } ) else { continue }
123
- guard let _ = snapshot. sectionIdentifiers. first ( where: { $0. identifier == previousSection. identifier } ) else { continue }
124
- snapshot. moveSection ( section, afterSection: previousSection)
125
- }
126
-
127
127
// Apply changes
128
128
129
129
apply ( snapshot, animated: true )
0 commit comments