Skip to content

Commit ad662ac

Browse files
authored
Remove main actor isolated from Updating (#20)
1 parent 70d9e82 commit ad662ac

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

Development/DataSourcesDemo/SingleSectionCollectionViewController.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import RxSwift
33
import SwiftUIHosting
44
import UIKit
55

6+
enum NonIsolated {
7+
8+
func run(collectionView: UICollectionView) {
9+
10+
let dataSource: SectionDataController<ModelA, CollectionViewAdapter> = .init(
11+
adapter: .init(collectionView: collectionView),
12+
displayingSection: 0
13+
)
14+
15+
}
16+
17+
}
18+
619
final class SingleSectionCollectionViewController: UIViewController, UICollectionViewDataSource,
720
UICollectionViewDelegateFlowLayout
821
{

Sources/DataSources/CollectionViewAdapter.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
open class CollectionViewAdapter<Element>: Updating {
11+
public struct CollectionViewAdapter<Element>: Updating {
1212

1313
public unowned let collectionView: UICollectionView
1414

@@ -20,27 +20,27 @@ open class CollectionViewAdapter<Element>: Updating {
2020
self.collectionView = collectionView
2121
}
2222

23-
open func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
23+
public func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
2424

2525
collectionView.insertItems(at: indexPaths)
2626
}
2727

28-
open func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
28+
public func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
2929

3030
collectionView.deleteItems(at: indexPaths)
3131
}
3232

33-
open func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
33+
public func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>) {
3434

3535
collectionView.reloadItems(at: indexPaths)
3636
}
3737

38-
open func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>) {
38+
public func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>) {
3939

4040
collectionView.moveItem(at: indexPath, to: newIndexPath)
4141
}
4242

43-
open func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) {
43+
public func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) {
4444

4545
if animated {
4646
collectionView.performBatchUpdates({
@@ -63,7 +63,7 @@ open class CollectionViewAdapter<Element>: Updating {
6363

6464
}
6565

66-
open func reload(completion: @escaping () -> Void) {
66+
public func reload(completion: @escaping () -> Void) {
6767

6868
collectionView.reloadData()
6969
completion()

Sources/DataSources/SectionDataController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final class SectionDataController<T: Differentiable & Sendable, A: Updati
103103
/// - adapter:
104104
/// - displayingSection:
105105
/// - isEqual: To use for decision that item should update.
106-
public init(itemType: ItemType.Type? = nil, adapter: AdapterType, displayingSection: Int = 0) {
106+
public init(itemType: ItemType.Type? = nil, adapter: consuming AdapterType, displayingSection: Int = 0) {
107107
self.adapter = adapter
108108
self.displayingSection = displayingSection
109109
}

Sources/DataSources/TableViewAdapter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import UIKit
1010

11-
open class TableViewAdapter<Element>: Updating {
11+
public struct TableViewAdapter<Element>: Updating {
1212

1313
public unowned let tableView: UITableView
1414

Sources/DataSources/Updating.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,28 @@ extension UpdateContext: Sendable where Element: Sendable {
5050
}
5151

5252

53-
@MainActor
54-
public protocol Updating: AnyObject {
53+
public protocol Updating: ~Copyable, Sendable {
5554

5655
associatedtype Target
5756
associatedtype Element
5857

5958
var target: Target { get }
6059

60+
@MainActor
6161
func insertItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)
6262

63+
@MainActor
6364
func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)
6465

66+
@MainActor
6567
func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext<Element>)
6668

69+
@MainActor
6770
func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext<Element>)
6871

72+
@MainActor
6973
func performBatch(in context: UpdateContext<Element>, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void)
7074

75+
@MainActor
7176
func reload(completion: @escaping () -> Void)
7277
}

0 commit comments

Comments
 (0)