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

Commit 1c7da9c

Browse files
committed
Make completion optional
1 parent 4f11c71 commit 1c7da9c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Sources/iOS/UICollectionView+Extensions.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ public extension UICollectionView {
1919
public func reload<T: Hashable>(
2020
changes: [Change<T>],
2121
section: Int = 0,
22-
completion: @escaping (Bool) -> Void) {
22+
completion: ((Bool) -> Void)? = nil) {
2323

2424
let changesWithIndexPath = IndexPathConverter().convert(changes: changes, section: section)
2525

2626
// reloadRows needs to be called outside the batch
2727

2828
performBatchUpdates({
2929
internalBatchUpdates(changesWithIndexPath: changesWithIndexPath)
30-
}, completion: completion)
30+
}, completion: { finished in
31+
completion?(finished)
32+
})
3133

3234
changesWithIndexPath.replaces.executeIfPresent {
3335
self.reloadItems(at: $0)

Sources/iOS/UITableView+Extensions.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public extension UITableView {
2525
insertionAnimation: UITableViewRowAnimation = .automatic,
2626
deletionAnimation: UITableViewRowAnimation = .automatic,
2727
replacementAnimation: UITableViewRowAnimation = .automatic,
28-
completion: @escaping (Bool) -> Void) {
28+
completion: ((Bool) -> Void)? = nil) {
2929

3030
let changesWithIndexPath = IndexPathConverter().convert(changes: changes, section: section)
3131

@@ -36,7 +36,9 @@ public extension UITableView {
3636
internalBatchUpdates(changesWithIndexPath: changesWithIndexPath,
3737
insertionAnimation: insertionAnimation,
3838
deletionAnimation: deletionAnimation)
39-
}, completion: completion)
39+
}, completion: { finished in
40+
completion?(finished)
41+
})
4042

4143
changesWithIndexPath.replaces.executeIfPresent {
4244
self.reloadRows(at: $0, with: replacementAnimation)
@@ -52,7 +54,7 @@ public extension UITableView {
5254
reloadRows(at: $0, with: replacementAnimation)
5355
}
5456

55-
completion(true)
57+
completion?(true)
5658
}
5759
}
5860

0 commit comments

Comments
 (0)