Skip to content

Commit

Permalink
Resolve Swift6 concurrency warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bigMOTOR committed Dec 20, 2024
1 parent 9adf16f commit 21cddf9
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 29 deletions.
43 changes: 21 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
{
"object": {
"pins": [
{
"package": "RxDataSources",
"repositoryURL": "https://github.com/RxSwiftCommunity/RxDataSources.git",
"state": {
"branch": null,
"revision": "241c62e7b578b2346c8b60efdf31b4eb2eab2966",
"version": "5.0.0"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "c8742ed97fc2f0c015a5ea5eddefb064cd7532d2",
"version": "6.0.0"
}
"originHash" : "36e62a8dccab1d7cd0f42fb6b7fa6880e52c06c8b648ab1394e1a7633724a2dd",
"pins" : [
{
"identity" : "rxdatasources",
"kind" : "remoteSourceControl",
"location" : "https://github.com/RxSwiftCommunity/RxDataSources.git",
"state" : {
"revision" : "241c62e7b578b2346c8b60efdf31b4eb2eab2966",
"version" : "5.0.0"
}
]
},
"version": 1
},
{
"identity" : "rxswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ReactiveX/RxSwift.git",
"state" : {
"revision" : "c7c7d2cf50a3211fe2843f76869c698e4e417930",
"version" : "6.8.0"
}
}
],
"version" : 3
}
37 changes: 37 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "DataDrivenRxDatasources",
platforms: [
.iOS(.v12)
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "DataDrivenRxDatasources",
targets: ["DataDrivenRxDatasources"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "6.0.0" )),
.package(url: "https://github.com/RxSwiftCommunity/RxDataSources.git", .upToNextMajor(from: "5.0.0" )),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "DataDrivenRxDatasources",
dependencies: ["RxSwift", "RxDataSources"],
resources: [
.copy("PrivacyInfo.xcprivacy")
]
),
.testTarget(
name: "DataDrivenRxDatasourcesTests",
dependencies: ["DataDrivenRxDatasources"]),
],
swiftLanguageModes: [.v6]
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public protocol CollectionCellViewModel {
}

// Base protocol for UICollectionViewCell subclass. It [subclass] should update UI on cellModel didSet using new value.
@MainActor
public protocol ModelledCollectionCell {
var cellModel: CollectionCellViewModel? { get set }
}
Expand All @@ -33,6 +34,7 @@ public protocol ModelledCollectionCell {

// extension to handle registering and dequeueing cells using viewModel
extension CollectionCellType {
@MainActor
func registerFor(collection: UICollectionView) {
switch self {
case .classType(let type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RxDataSources

extension Reactive where Base: UICollectionView {
// MARK: - Reload
@MainActor
public func bind<S>(sections: Driver<[CollectionSectionModel<S>]>) -> Disposable {
return CompositeDisposable(disposables: [
sections
Expand All @@ -22,6 +23,7 @@ extension Reactive where Base: UICollectionView {
])
}

@MainActor
public func bind<S>(sections: Driver<[CollectionSectionModel<S>]>) -> Disposable where Base: CollectionViewFlowLayout {
return CompositeDisposable(disposables: [
sections
Expand All @@ -33,6 +35,7 @@ extension Reactive where Base: UICollectionView {
}

// MARK: - Animatable
@MainActor
public func bind<S>(sections: Driver<[AnimatableCollectionSectionModel<S>]>, animationConfiguration: AnimationConfiguration = AnimationConfiguration()) -> Disposable {
return CompositeDisposable(disposables: [
sections
Expand All @@ -43,6 +46,7 @@ extension Reactive where Base: UICollectionView {
])
}

@MainActor
public func bind<S>(sections: Driver<[AnimatableCollectionSectionModel<S>]>, animationConfiguration: AnimationConfiguration = AnimationConfiguration()) -> Disposable where Base: CollectionViewFlowLayout {
return CompositeDisposable(disposables: [
sections
Expand All @@ -64,6 +68,7 @@ extension Reactive where Base: UICollectionView {
}

// MARK: - Cell Actions
@MainActor
private func _bindActions() -> Disposable {
let collectionView = base
return CompositeDisposable(disposables: [
Expand All @@ -82,13 +87,15 @@ extension Reactive where Base: UICollectionView {
}

// MARK: - Add Delegate
@MainActor
private func _addDelegate(_ delegate: CollectionViewControllerDelegateProxy = CollectionViewControllerDelegateProxy()) -> Disposable {
base.delegate = delegate
return Disposables.create { [delegate] in _ = delegate}
}
}

// MARK: - Cell registration
@MainActor
private func _registerCells<S: SectionModelType>(for collectionView: UICollectionView) -> ([S]) -> () where S.Item: CollectionCellViewModelWrapper {
return { sections in
sections
Expand All @@ -100,13 +107,15 @@ private func _registerCells<S: SectionModelType>(for collectionView: UICollectio
}

// MARK: - DataSources
@MainActor
private func _reloadDataSource<S>() -> RxCollectionViewSectionedReloadDataSource<CollectionSectionModel<S>> {
return RxCollectionViewSectionedReloadDataSource<CollectionSectionModel<S>>(
configureCell: { (_, cv, indexPath, model) in _configureCell(cv: cv, indexPath: indexPath, model: model) },
canMoveItemAtIndexPath: _canMoveRowAtIndexPath
)
}

@MainActor
private func _animatableDataSource<S>(animationConfiguration: AnimationConfiguration) -> RxCollectionViewSectionedAnimatedDataSource<AnimatableCollectionSectionModel<S>> {
return RxCollectionViewSectionedAnimatedDataSource<AnimatableCollectionSectionModel<S>>(
animationConfiguration: animationConfiguration,
Expand All @@ -116,19 +125,22 @@ private func _animatableDataSource<S>(animationConfiguration: AnimationConfigura
}

// MARK: - Configurations
@MainActor
private func _configureCell<C: CollectionCellViewModelWrapper>(cv: UICollectionView, indexPath: IndexPath, model: C) -> UICollectionViewCell {
let cell = cv.dequeueReusableCell(withReuseIdentifier: model.base.cellViewClass.identifier, for: indexPath)
guard var modeledCell = cell as? ModelledCollectionCell else { return cell }
modeledCell.cellModel = model.base
return cell
}

@MainActor
private func _canMoveRowAtIndexPath(dataSource: SectionedViewDataSourceType, indexPath: IndexPath) -> Bool {
guard let model = try? dataSource.model(at: indexPath) as? CollectionCellViewModelWrapper else { return false }
return model.base is DragReorderedType
}

// MARK: - CollectionViewControllerDelegateProxy
@MainActor
private class CollectionViewControllerDelegateProxy: NSObject, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {
if
Expand Down Expand Up @@ -159,6 +171,7 @@ private class CollectionViewControllerDelegateProxy: NSObject, UICollectionViewD
}

// MARK: - CollectionViewControllerDelegateProxy + UICollectionViewDelegateFlowLayout
@MainActor
private final class FlowLayoutCollectionViewControllerDelegateProxy: CollectionViewControllerDelegateProxy, UICollectionViewDelegateFlowLayout {
let collectionViewSizeForItemAt: (UICollectionView, UICollectionViewLayout, IndexPath) -> CGSize

Expand Down
1 change: 1 addition & 0 deletions Sources/DataDrivenRxDatasources/ContextMenuAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public struct ContextMenuAction {

@available(iOS 13.0, *)
extension ContextMenuAction {
@MainActor
var asUIAction: UIAction {
return .init(title: title,
image: image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public protocol DragReorderedType {}
// Protocol for UITableViewCell to update constraints and redraw cell
import UIKit.UITableView

@MainActor
public protocol ExpandableCell {
var reload: (() -> Void)? { get set }
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/DataDrivenRxDatasources/TableView/CellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public protocol CellViewModel {
}

// Base protocol for UITableViewCell subclass. It [subclass] should update UI on cellModel didSet using new value.
@MainActor
public protocol ModelledCell {
var cellModel: CellViewModel? { get set }
}
Expand All @@ -33,6 +34,7 @@ public protocol ModelledCell {

// extension to handle registering and dequeueing cells using viewModel
extension CellType {
@MainActor
func registerFor(table: UITableView) {
switch self {
case .classType(let type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import RxDataSources

@available(iOS 13.0, *)
public struct DiffableTableSectionModel<Section: Hashable> {
public struct DiffableTableSectionModel<Section: Hashable & Sendable> {
public var model: Section
public var items: [DiffableCellViewModel]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol ExtendedSectionedViewDataSourceType: SectionedViewDataSourceType {
func sectionModel(at index: Int) -> Section?
}

extension TableViewSectionedDataSource: ExtendedSectionedViewDataSourceType where Section: ModelType {
extension TableViewSectionedDataSource: @preconcurrency ExtendedSectionedViewDataSourceType where Section: ModelType {
func sectionModel(at index: Int) -> Section.Model? {
return sectionModels[index].model
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public protocol HeaderFooterViewModel {
}

// Base protocol for UITableViewCell subclass. It [subclass] should update UI on cellModel didSet using new value.
@MainActor
public protocol ModelledHeaderFooterView {
var headerFooterModel: HeaderFooterViewModel? { get set }
}
Expand All @@ -33,6 +34,7 @@ public protocol ModelledHeaderFooterView {

// extension to handle registering and dequeueing cells using viewModel
extension HeaderFooterType {
@MainActor
func registerFor(table: UITableView) {
switch self {
case .classType(let type):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ extension AnimatableCellViewModel: IdentifiableType, Equatable {

/// A wrapper for CellViewModel, that allows to use it with DiffableSectionModel
@available(iOS 13.0, *)
public struct DiffableCellViewModel: CellViewModelWrapper {
public struct DiffableCellViewModel: CellViewModelWrapper, Sendable {
var base: CellViewModel {
return _base
}

private let _base: IdentifiableCellViewModel
private let _base: IdentifiableCellViewModel & Sendable

init(base: IdentifiableCellViewModel) {
init(base: IdentifiableCellViewModel & Sendable) {
self._base = base
}
}
Expand Down
14 changes: 14 additions & 0 deletions Sources/DataDrivenRxDatasources/TableView/RxTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RxDataSources

extension Reactive where Base: UITableView {
// MARK: - Reload
@MainActor
public func bind<S>(sections: Driver<[TableSectionModel<S>]>) -> Disposable {
let dataSource: RxTableViewSectionedReloadDataSource<TableSectionModel<S>> = _reloadDataSource()
return CompositeDisposable(disposables: [
Expand All @@ -24,6 +25,7 @@ extension Reactive where Base: UITableView {
}

// MARK: - Animatable
@MainActor
public func bind<S>(sections: Driver<[AnimatableTableSectionModel<S>]>, animationConfiguration: AnimationConfiguration = AnimationConfiguration()) -> Disposable {
let dataSource: RxTableViewSectionedAnimatedDataSource<AnimatableTableSectionModel<S>> = _animatableDataSource(animationConfiguration: animationConfiguration)
return CompositeDisposable(disposables: [
Expand All @@ -36,6 +38,7 @@ extension Reactive where Base: UITableView {
}

@available(iOS 13.0, *)
@MainActor
public func bind<S>(sections: Driver<[DiffableTableSectionModel<S>]>, rowAnimation: UITableView.RowAnimation = .automatic) -> Disposable {
let dataSource: RxTableViewDiffableDataSource<S, DiffableCellViewModel> = _diffableDataSource(tableView: base, rowAnimation: rowAnimation)
var firstLoad = true
Expand Down Expand Up @@ -63,6 +66,7 @@ extension Reactive where Base: UITableView {
}

// MARK: - Cell Actions
@MainActor
private func _bindActions() -> Disposable {
let tableView = base
return CompositeDisposable(disposables: [
Expand Down Expand Up @@ -96,6 +100,7 @@ extension Reactive where Base: UITableView {
}

// MARK: - Add Delegate
@MainActor
private func _addDelegate<DataSource: ExtendedSectionedViewDataSourceType & AnyObject>(using dataSource: DataSource) -> Disposable {
let delegate = TableViewControllerDelegateProxy(dataSource: dataSource)
base.delegate = delegate
Expand All @@ -104,6 +109,7 @@ extension Reactive where Base: UITableView {
}

// MARK: - Cell registration
@MainActor
private func _registerReusables<S: SectionModelType & ModelType>(for tableView: UITableView) -> ([S]) -> () where S.Item: CellViewModelWrapper {
return { sections in
sections
Expand All @@ -127,6 +133,7 @@ private func _registerReusables<S: SectionModelType & ModelType>(for tableView:
}

// MARK: - DataSources
@MainActor
private func _reloadDataSource<S>() -> RxTableViewSectionedReloadDataSource<TableSectionModel<S>> {
return RxTableViewSectionedReloadDataSource<TableSectionModel<S>>(
configureCell: { (_, tv, indexPath, model) in _configureCell(tv: tv, indexPath: indexPath, model: model) },
Expand All @@ -137,6 +144,7 @@ private func _reloadDataSource<S>() -> RxTableViewSectionedReloadDataSource<Tabl
)
}

@MainActor
private func _animatableDataSource<S>(animationConfiguration: AnimationConfiguration) -> RxTableViewSectionedAnimatedDataSource<AnimatableTableSectionModel<S>> {
return RxTableViewSectionedAnimatedDataSource<AnimatableTableSectionModel<S>>(
animationConfiguration: animationConfiguration,
Expand All @@ -149,6 +157,7 @@ private func _animatableDataSource<S>(animationConfiguration: AnimationConfigura
}

@available(iOS 13.0, *)
@MainActor
private func _diffableDataSource<S>(tableView: UITableView, rowAnimation: UITableView.RowAnimation) -> RxTableViewDiffableDataSource<S, DiffableCellViewModel> {
let dataSource = RxTableViewDiffableDataSource<S, DiffableCellViewModel>(
tableView: tableView,
Expand All @@ -162,6 +171,7 @@ private func _diffableDataSource<S>(tableView: UITableView, rowAnimation: UITabl
}

// MARK: - Configurations
@MainActor
private func _configureCell<C: CellViewModelWrapper>(tv: UITableView, indexPath: IndexPath, model: C) -> UITableViewCell {
let cell = tv.dequeueReusableCell(withIdentifier: model.base.cellViewClass.identifier, for: indexPath)
guard var modeledCell = cell as? ModelledCell else { return cell }
Expand All @@ -171,10 +181,12 @@ private func _configureCell<C: CellViewModelWrapper>(tv: UITableView, indexPath:
return cell
}

@MainActor
private func _titleForHeaderInSection<DataSource: ExtendedSectionedViewDataSourceType>(dataSource: DataSource, index: Int) -> String? {
return (dataSource.sectionModel(at: index) as? SectionHeaderTitleType)?.sectionHeaderTitle
}

@MainActor
private func _titleForFooterInSection<DataSource: ExtendedSectionedViewDataSourceType>(dataSource: DataSource, index: Int) -> String? {
return (dataSource.sectionModel(at: index) as? SectionFooterTitleType)?.sectionFooterTitle
}
Expand Down Expand Up @@ -279,6 +291,7 @@ private final class TableViewControllerDelegateProxy<DataSource: ExtendedSection
}
}

@MainActor
private func _headerFooterView(tableView: UITableView) -> (HeaderFooterViewModel) -> UITableViewHeaderFooterView? {
return { model in
let view = tableView.dequeueReusableHeaderFooterView(withIdentifier: model.headerFooterViewClass.identifier)
Expand All @@ -289,6 +302,7 @@ private func _headerFooterView(tableView: UITableView) -> (HeaderFooterViewModel
}

private extension SwipeAction {
@MainActor
var contextualAction: UIContextualAction {
let contextualAction = UIContextualAction(style: style.contextualActionStyle, title: title) { _, _, completionHandler in
handler()
Expand Down
Loading

0 comments on commit 21cddf9

Please sign in to comment.