From ad662acf81c077334000a732661afbcca217776a Mon Sep 17 00:00:00 2001 From: Hiroshi Kimura Date: Mon, 25 Nov 2024 17:27:01 +0900 Subject: [PATCH] Remove main actor isolated from Updating (#20) --- .../SingleSectionCollectionViewController.swift | 13 +++++++++++++ Sources/DataSources/CollectionViewAdapter.swift | 14 +++++++------- Sources/DataSources/SectionDataController.swift | 2 +- Sources/DataSources/TableViewAdapter.swift | 2 +- Sources/DataSources/Updating.swift | 9 +++++++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Development/DataSourcesDemo/SingleSectionCollectionViewController.swift b/Development/DataSourcesDemo/SingleSectionCollectionViewController.swift index a488d5c..bf84910 100644 --- a/Development/DataSourcesDemo/SingleSectionCollectionViewController.swift +++ b/Development/DataSourcesDemo/SingleSectionCollectionViewController.swift @@ -3,6 +3,19 @@ import RxSwift import SwiftUIHosting import UIKit +enum NonIsolated { + + func run(collectionView: UICollectionView) { + + let dataSource: SectionDataController = .init( + adapter: .init(collectionView: collectionView), + displayingSection: 0 + ) + + } + +} + final class SingleSectionCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { diff --git a/Sources/DataSources/CollectionViewAdapter.swift b/Sources/DataSources/CollectionViewAdapter.swift index d276a47..4e4816c 100644 --- a/Sources/DataSources/CollectionViewAdapter.swift +++ b/Sources/DataSources/CollectionViewAdapter.swift @@ -8,7 +8,7 @@ import UIKit -open class CollectionViewAdapter: Updating { +public struct CollectionViewAdapter: Updating { public unowned let collectionView: UICollectionView @@ -20,27 +20,27 @@ open class CollectionViewAdapter: Updating { self.collectionView = collectionView } - open func insertItems(at indexPaths: [IndexPath], in context: UpdateContext) { + public func insertItems(at indexPaths: [IndexPath], in context: UpdateContext) { collectionView.insertItems(at: indexPaths) } - open func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext) { + public func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext) { collectionView.deleteItems(at: indexPaths) } - open func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext) { + public func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext) { collectionView.reloadItems(at: indexPaths) } - open func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext) { + public func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext) { collectionView.moveItem(at: indexPath, to: newIndexPath) } - open func performBatch(in context: UpdateContext, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) { + public func performBatch(in context: UpdateContext, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) { if animated { collectionView.performBatchUpdates({ @@ -63,7 +63,7 @@ open class CollectionViewAdapter: Updating { } - open func reload(completion: @escaping () -> Void) { + public func reload(completion: @escaping () -> Void) { collectionView.reloadData() completion() diff --git a/Sources/DataSources/SectionDataController.swift b/Sources/DataSources/SectionDataController.swift index b3faa6d..73bc45d 100644 --- a/Sources/DataSources/SectionDataController.swift +++ b/Sources/DataSources/SectionDataController.swift @@ -103,7 +103,7 @@ public final class SectionDataController: Updating { +public struct TableViewAdapter: Updating { public unowned let tableView: UITableView diff --git a/Sources/DataSources/Updating.swift b/Sources/DataSources/Updating.swift index 206db3f..576e166 100644 --- a/Sources/DataSources/Updating.swift +++ b/Sources/DataSources/Updating.swift @@ -50,23 +50,28 @@ extension UpdateContext: Sendable where Element: Sendable { } -@MainActor -public protocol Updating: AnyObject { +public protocol Updating: ~Copyable, Sendable { associatedtype Target associatedtype Element var target: Target { get } + @MainActor func insertItems(at indexPaths: [IndexPath], in context: UpdateContext) + @MainActor func deleteItems(at indexPaths: [IndexPath], in context: UpdateContext) + @MainActor func reloadItems(at indexPaths: [IndexPath], in context: UpdateContext) + @MainActor func moveItem(at indexPath: IndexPath, to newIndexPath: IndexPath, in context: UpdateContext) + @MainActor func performBatch(in context: UpdateContext, animated: Bool, updates: @escaping () -> Void, completion: @escaping () -> Void) + @MainActor func reload(completion: @escaping () -> Void) }