Skip to content

Commit f577332

Browse files
committed
refinements and docs for completion closures
1 parent e677f03 commit f577332

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/CollectionViewDriver.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import UIKit
2121
@MainActor
2222
public final class CollectionViewDriver: NSObject {
2323
/// A closure type used to notify callers of collection view updates.
24-
public typealias DidUpdate = (CollectionViewDriver) -> Void
24+
public typealias DidUpdate = @MainActor (CollectionViewDriver) -> Void
2525

2626
/// The collection view.
2727
public let view: UICollectionView

Sources/DiffableDataSource.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ import UIKit
1616

1717
extension AnyHashable: @unchecked Sendable { }
1818

19-
struct UncheckedCompletion: @unchecked Sendable {
19+
/// This is a workaround for the concurrency warning:
20+
/// _"Capture of 'completion' with non-sendable type in a `@Sendable` closure"_
21+
///
22+
/// Used below when applying snapshots.
23+
/// This is safe because we know the completion block
24+
/// will always be called on the main thread by UIKit.
25+
private struct UncheckedCompletion: @unchecked Sendable {
2026
typealias Block = () -> Void
2127

2228
let block: Block?
@@ -37,7 +43,7 @@ struct UncheckedCompletion: @unchecked Sendable {
3743
final class DiffableDataSource: UICollectionViewDiffableDataSource<AnyHashable, AnyHashable> {
3844
typealias Snapshot = NSDiffableDataSourceSnapshot<AnyHashable, AnyHashable>
3945

40-
typealias SnapshotCompletion = () -> Void
46+
typealias SnapshotCompletion = @MainActor () -> Void
4147

4248
// Avoid retaining the collection view, we know it is owned and kept alive by the driver.
4349
// Thus, unowned is safe here.
@@ -252,7 +258,7 @@ final class DiffableDataSource: UICollectionViewDiffableDataSource<AnyHashable,
252258
}
253259
}
254260

255-
func _applyReloadSnapshot(_ snapshot: Snapshot, completion: UncheckedCompletion) {
261+
private func _applyReloadSnapshot(_ snapshot: Snapshot, completion: UncheckedCompletion) {
256262
self._performOnDiffingQueueIfNeeded {
257263
// UIKit guarantees `completion` is called on the main queue.
258264
self.applySnapshotUsingReloadData(snapshot, completion: completion.block)

0 commit comments

Comments
 (0)