@@ -13,6 +13,7 @@ public enum DifferentiatorError
13
13
, CustomDebugStringConvertible {
14
14
case DuplicateItem( item: Any )
15
15
case DuplicateSection( section: Any )
16
+ case InvalidInitializerImplementation( section: Any , expectedItems: Any , expectedIdentifier: Any )
16
17
}
17
18
18
19
extension DifferentiatorError {
@@ -22,6 +23,10 @@ extension DifferentiatorError {
22
23
return " Duplicate item \( item) "
23
24
case let . DuplicateSection( section) :
24
25
return " Duplicate section \( section) "
26
+ case let InvalidInitializerImplementation( section, expectedItems, expectedIdentifier) :
27
+ return " Wrong initializer implementation for: \( section) \n " +
28
+ " Expected it should return items: \( expectedItems) \n " +
29
+ " Expected it should have id: \( expectedIdentifier) "
25
30
}
26
31
}
27
32
}
@@ -284,6 +289,16 @@ public func differencesForSectionedView<S: AnimatableSectionModelType>(
284
289
return result
285
290
}
286
291
292
+ private extension AnimatableSectionModelType {
293
+ init ( safeOriginal: Self , safeItems: [ Item ] ) throws {
294
+ self . init ( original: safeOriginal, items: safeItems)
295
+
296
+ if self . items != safeItems || self . identity != safeOriginal. identity {
297
+ throw DifferentiatorError . InvalidInitializerImplementation ( section: self , expectedItems: safeItems, expectedIdentifier: safeOriginal. identity)
298
+ }
299
+ }
300
+ }
301
+
287
302
struct CommandGenerator < S: AnimatableSectionModelType > {
288
303
let initialSections : [ S ]
289
304
let finalSections : [ S ]
@@ -545,7 +560,7 @@ struct CommandGenerator<S: AnimatableSectionModelType> {
545
560
}
546
561
}
547
562
548
- afterDeleteState. append ( S ( original : initialSection, items : afterDeleteItems) )
563
+ afterDeleteState. append ( try S ( safeOriginal : initialSection, safeItems : afterDeleteItems) )
549
564
}
550
565
// }
551
566
@@ -620,7 +635,9 @@ struct CommandGenerator<S: AnimatableSectionModelType> {
620
635
items. append ( self . finalSections [ finalIndex. sectionIndex] . items [ finalIndex. itemIndex] )
621
636
}
622
637
623
- return S ( original: s, items: items)
638
+ let modifiedSection = try S ( safeOriginal: s, safeItems: items)
639
+
640
+ return modifiedSection
624
641
}
625
642
else {
626
643
try rxPrecondition ( false , " This is weird, this shouldn't happen " )
0 commit comments