Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

Commit efaa271

Browse files
committed
Update data source model
1 parent d65be45 commit efaa271

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/iOS/UICollectionView+Extensions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ public extension UICollectionView {
1515
/// - Parameters:
1616
/// - changes: The changes from diff
1717
/// - section: The section that all calculated IndexPath belong
18+
/// - updateData: Update your data source model
1819
/// - completion: Called when operation completes
1920
public func reload<T: Hashable>(
2021
changes: [Change<T>],
2122
section: Int = 0,
23+
updateData: () -> Void,
2224
completion: ((Bool) -> Void)? = nil) {
2325

2426
let changesWithIndexPath = IndexPathConverter().convert(changes: changes, section: section)
2527

2628
performBatchUpdates({
29+
updateData()
2730
insideUpdate(changesWithIndexPath: changesWithIndexPath)
2831
}, completion: { finished in
2932
completion?(finished)

Sources/iOS/UITableView+Extensions.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ public extension UITableView {
1818
/// - insertionAnimation: The animation for insert rows
1919
/// - deletionAnimation: The animation for delete rows
2020
/// - replacementAnimation: The animation for reload rows
21+
/// - updateData: Update your data source model
2122
/// - completion: Called when operation completes
2223
public func reload<T: Hashable>(
2324
changes: [Change<T>],
2425
section: Int = 0,
2526
insertionAnimation: UITableView.RowAnimation = .automatic,
2627
deletionAnimation: UITableView.RowAnimation = .automatic,
2728
replacementAnimation: UITableView.RowAnimation = .automatic,
29+
updateData: () -> Void,
2830
completion: ((Bool) -> Void)? = nil) {
2931

3032
let changesWithIndexPath = IndexPathConverter().convert(changes: changes, section: section)
3133

3234
unifiedPerformBatchUpdates({
35+
updateData()
3336
self.insideUpdate(
3437
changesWithIndexPath: changesWithIndexPath,
3538
insertionAnimation: insertionAnimation,
@@ -46,16 +49,16 @@ public extension UITableView {
4649
// MARK: - Helper
4750

4851
private func unifiedPerformBatchUpdates(
49-
_ updates: (() -> Void)?,
50-
completion: ((Bool) -> Void)? = nil) {
52+
_ updates: (() -> Void),
53+
completion: (@escaping (Bool) -> Void)) {
5154

5255
if #available(iOS 11, tvOS 11, *) {
5356
performBatchUpdates(updates, completion: completion)
5457
} else {
5558
beginUpdates()
56-
updates?()
59+
updates()
5760
endUpdates()
58-
completion?(true)
61+
completion(true)
5962
}
6063
}
6164

0 commit comments

Comments
 (0)