Skip to content

Commit 5cef907

Browse files
committed
Changes DEBUG mode behavior for duplicate items in data source from asserting to printing a warning. #45
1 parent 4072d82 commit 5cef907

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Sources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public class RxCollectionViewSectionedAnimatedDataSource<S: AnimatableSectionMod
5050
}
5151
}
5252
catch let e {
53+
#if DEBUG
54+
print("Error while binding data animated: \(e)\nFallback to normal `reloadData` behavior.")
5355
rxDebugFatalError(e)
56+
#endif
5457
self.setSections(newSections)
5558
collectionView.reloadData()
5659
}

Sources/DataSources/Differentiator.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ func indexSections<S: AnimatableSectionModelType>(sections: [S]) throws -> [S.Id
104104
for (i, section) in sections.enumerate() {
105105
guard indexedSections[section.identity] == nil else {
106106
#if DEBUG
107-
precondition(indexedSections[section.identity] == nil, "Section \(section) has already been indexed at \(indexedSections[section.identity]!)")
107+
if indexedSections[section.identity] != nil {
108+
print("Section \(section) has already been indexed at \(indexedSections[section.identity]!)")
109+
}
108110
#endif
109111
throw DifferentiatorError.DuplicateItem(item: section)
110112
}
@@ -127,7 +129,9 @@ func indexSectionItems<S: AnimatableSectionModelType>(sections: [S]) throws -> [
127129
for (j, item) in sections[i].items.enumerate() {
128130
guard indexedItems[item.identity] == nil else {
129131
#if DEBUG
130-
precondition(indexedItems[item.identity] == nil, "Item \(item) has already been indexed at \(indexedItems[item.identity]!)" )
132+
if indexedItems[item.identity] != nil {
133+
print("Item \(item) has already been indexed at \(indexedItems[item.identity]!)" )
134+
}
131135
#endif
132136
throw DifferentiatorError.DuplicateItem(item: item)
133137
}

0 commit comments

Comments
 (0)