@@ -16,7 +16,13 @@ import UIKit
16
16
17
17
extension AnyHashable : @unchecked Sendable { }
18
18
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 {
20
26
typealias Block = ( ) -> Void
21
27
22
28
let block : Block ?
@@ -37,7 +43,7 @@ struct UncheckedCompletion: @unchecked Sendable {
37
43
final class DiffableDataSource : UICollectionViewDiffableDataSource < AnyHashable , AnyHashable > {
38
44
typealias Snapshot = NSDiffableDataSourceSnapshot < AnyHashable , AnyHashable >
39
45
40
- typealias SnapshotCompletion = ( ) -> Void
46
+ typealias SnapshotCompletion = @ MainActor ( ) -> Void
41
47
42
48
// Avoid retaining the collection view, we know it is owned and kept alive by the driver.
43
49
// Thus, unowned is safe here.
@@ -252,7 +258,7 @@ final class DiffableDataSource: UICollectionViewDiffableDataSource<AnyHashable,
252
258
}
253
259
}
254
260
255
- func _applyReloadSnapshot( _ snapshot: Snapshot , completion: UncheckedCompletion ) {
261
+ private func _applyReloadSnapshot( _ snapshot: Snapshot , completion: UncheckedCompletion ) {
256
262
self . _performOnDiffingQueueIfNeeded {
257
263
// UIKit guarantees `completion` is called on the main queue.
258
264
self . applySnapshotUsingReloadData ( snapshot, completion: completion. block)
0 commit comments