Skip to content

Commit

Permalink
Fix Swift concurrency (#722)
Browse files Browse the repository at this point in the history
* fix actor isolation
* fix tests
  • Loading branch information
kitwtnb authored Aug 10, 2024
1 parent 189e900 commit 22b92d5
Show file tree
Hide file tree
Showing 24 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions Parchment/Classes/PageViewCoordinator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit

@available(iOS 14.0, *)
@MainActor
final class PageViewCoordinator: PagingViewControllerDataSource, PagingViewControllerDelegate {
final class WeakReference<T: AnyObject> {
weak var value: T?
Expand Down
1 change: 1 addition & 0 deletions Parchment/Classes/PageViewManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

@MainActor
final class PageViewManager {
weak var dataSource: PageViewManagerDataSource?
weak var delegate: PageViewManagerDelegate?
Expand Down
1 change: 1 addition & 0 deletions Parchment/Classes/PagingController.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit

protocol PagingControllerSizeDelegate: AnyObject {
@MainActor
func width(for: PagingItem, isSelected: Bool) -> CGFloat
}

Expand Down
3 changes: 2 additions & 1 deletion Parchment/Classes/PagingStaticDataSource.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation
import UIKit

class PagingStaticDataSource: PagingViewControllerInfiniteDataSource {
@MainActor
final class PagingStaticDataSource: PagingViewControllerInfiniteDataSource {
private(set) var items: [PagingItem] = []
private let viewControllers: [UIViewController]

Expand Down
1 change: 1 addition & 0 deletions Parchment/Enums/InvalidationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UIKit
/// called and we can use we can use this to determine exactly how
/// much we need to invalidate by adding together the states each
/// time a new context is invalidated.
@MainActor
public enum InvalidationState {
case nothing
case everything
Expand Down
2 changes: 2 additions & 0 deletions Parchment/Protocols/CollectionView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

@MainActor
protocol CollectionViewLayout: AnyObject {
var state: PagingState { get set }
var visibleItems: PagingItems { get set }
Expand All @@ -13,6 +14,7 @@ protocol CollectionViewLayout: AnyObject {

extension PagingCollectionViewLayout: CollectionViewLayout {}

@MainActor
protocol CollectionView: AnyObject {
var indexPathsForVisibleItems: [IndexPath] { get }
var isDragging: Bool { get }
Expand Down
2 changes: 2 additions & 0 deletions Parchment/Protocols/PageViewControllerDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public protocol PageViewControllerDataSource: AnyObject {
/// - Parameters:
/// - pageViewController: The `PageViewController` instance.
/// - viewController: The current view controller.
@MainActor
func pageViewController(
_ pageViewController: PageViewController,
viewControllerBeforeViewController viewController: UIViewController
Expand All @@ -18,6 +19,7 @@ public protocol PageViewControllerDataSource: AnyObject {
/// - Parameters:
/// - pageViewController: The `PageViewController` instance.
/// - viewController: The current view controller.
@MainActor
func pageViewController(
_ pageViewController: PageViewController,
viewControllerAfterViewController viewController: UIViewController
Expand Down
3 changes: 3 additions & 0 deletions Parchment/Protocols/PageViewControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public protocol PageViewControllerDelegate: AnyObject {
/// scrolling from.
/// - destinationViewController: The view controller the user is
/// scrolling towards.
@MainActor
func pageViewController(
_ pageViewController: PageViewController,
willStartScrollingFrom startingViewController: UIViewController,
Expand All @@ -30,6 +31,7 @@ public protocol PageViewControllerDelegate: AnyObject {
/// towards one of the edges.
/// - progress: The progress of the scroll transition. Between 0
/// and 1.
@MainActor
func pageViewController(
_ pageViewController: PageViewController,
isScrollingFrom startingViewController: UIViewController,
Expand All @@ -47,6 +49,7 @@ public protocol PageViewControllerDelegate: AnyObject {
/// scrolling towards.
/// - transitionSuccessful: A boolean indicating whether the
/// transition completed, or was cancelled by the user.
@MainActor
func pageViewController(
_ pageViewController: PageViewController,
didFinishScrollingFrom startingViewController: UIViewController,
Expand Down
1 change: 1 addition & 0 deletions Parchment/Protocols/PageViewManagerDataSource.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

@MainActor
protocol PageViewManagerDataSource: AnyObject {
func viewControllerBefore(_ viewController: UIViewController) -> UIViewController?
func viewControllerAfter(_ viewController: UIViewController) -> UIViewController?
Expand Down
1 change: 1 addition & 0 deletions Parchment/Protocols/PageViewManagerDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import UIKit

@MainActor
protocol PageViewManagerDelegate: AnyObject {
func scrollForward()
func scrollReverse()
Expand Down
2 changes: 2 additions & 0 deletions Parchment/Protocols/PagingLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import Foundation
/// Used to be able to initialize a layout based on the type defined
/// in the menuLayoutClass property.
protocol PagingLayout {
@MainActor
init()
}

@MainActor
func createLayout<T>(layout: T.Type) -> T where T: PagingLayout {
return layout.init()
}
2 changes: 2 additions & 0 deletions Parchment/Protocols/PagingMenuDataSource.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation

public protocol PagingMenuDataSource: AnyObject {
@MainActor
func pagingItemBefore(pagingItem: PagingItem) -> PagingItem?
@MainActor
func pagingItemAfter(pagingItem: PagingItem) -> PagingItem?
}
2 changes: 2 additions & 0 deletions Parchment/Protocols/PagingMenuDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation

public protocol PagingMenuDelegate: AnyObject {
@MainActor
func selectContent(pagingItem: PagingItem, direction: PagingDirection, animated: Bool)
@MainActor
func removeContent()
}
3 changes: 3 additions & 0 deletions Parchment/Protocols/PagingViewControllerDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol PagingViewControllerDataSource: AnyObject {
/// - Parameter pagingViewController: The `PagingViewController`
/// instance
/// - Returns: The number of view controllers
@MainActor
func numberOfViewControllers(in pagingViewController: PagingViewController) -> Int

/// Return the view controller accociated with a given index. This
Expand All @@ -24,12 +25,14 @@ public protocol PagingViewControllerDataSource: AnyObject {
/// instance
/// - Parameter index: The index of a given `PagingItem`
/// - Returns: The view controller for the given index
@MainActor
func pagingViewController(_: PagingViewController, viewControllerAt index: Int) -> UIViewController

/// Return the `PagingItem` instance for a given index
///
/// - Parameter pagingViewController: The `PagingViewController`
/// instance
/// - Returns: The `PagingItem` instance
@MainActor
func pagingViewController(_: PagingViewController, pagingItemAt index: Int) -> PagingItem
}
4 changes: 4 additions & 0 deletions Parchment/Protocols/PagingViewControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public protocol PagingViewControllerDelegate: AnyObject {
/// - Parameter destinationViewController: The view controller for
/// the upcoming paging item
/// - Parameter progress: The progress of the scroll transition
@MainActor
func pagingViewController(
_: PagingViewController,
isScrollingFromItem currentPagingItem: PagingItem,
Expand All @@ -30,6 +31,7 @@ public protocol PagingViewControllerDelegate: AnyObject {
/// current paging item
/// - Parameter destinationViewController: The view controller for
/// the upcoming paging item
@MainActor
func pagingViewController(
_: PagingViewController,
willScrollToItem pagingItem: PagingItem,
Expand All @@ -46,6 +48,7 @@ public protocol PagingViewControllerDelegate: AnyObject {
/// the upcoming paging item
/// - Parameter transitionSuccessful: Boolean that indicates whether
/// the transition to the paging item was successful or not
@MainActor
func pagingViewController(
_ pagingViewController: PagingViewController,
didScrollToItem pagingItem: PagingItem,
Expand All @@ -58,6 +61,7 @@ public protocol PagingViewControllerDelegate: AnyObject {
///
/// - Parameter pagingViewController: The `PagingViewController` instance
/// - Parameter pagingItem: The item that was selected.
@MainActor
func pagingViewController(
_ pagingViewController: PagingViewController,
didSelectItem pagingItem: PagingItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public protocol PagingViewControllerInfiniteDataSource: AnyObject {
/// instance
/// - Parameter viewControllerForPagingItem: A `PagingItem` instance
/// - Returns: The view controller for the `PagingItem` instance
@MainActor
func pagingViewController(_: PagingViewController, viewControllerFor pagingItem: PagingItem) -> UIViewController

/// The `PagingItem` that comes before a given `PagingItem`
Expand All @@ -26,6 +27,7 @@ public protocol PagingViewControllerInfiniteDataSource: AnyObject {
/// - Returns: The `PagingItem` that appears before the given
/// `PagingItem`, or `nil` to indicate that no more progress can be
/// made in that direction.
@MainActor
func pagingViewController(_: PagingViewController, itemBefore pagingItem: PagingItem) -> PagingItem?

/// The `PagingItem` that comes after a given `PagingItem`
Expand All @@ -36,5 +38,6 @@ public protocol PagingViewControllerInfiniteDataSource: AnyObject {
/// - Returns: The `PagingItem` that appears after the given
/// `PagingItem`, or `nil` to indicate that no more progress can be
/// made in that direction.
@MainActor
func pagingViewController(_: PagingViewController, itemAfter pagingItem: PagingItem) -> PagingItem?
}
1 change: 1 addition & 0 deletions Parchment/Structs/Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import SwiftUI
/// initializers are closures that return the view hierarchy for
/// the header and body of the page, respectively.
@available(iOS 14.0, *)
@MainActor
public struct Page {
let reuseIdentifier: String
let pageIdentifier: String?
Expand Down
1 change: 1 addition & 0 deletions Parchment/Structs/PagingDistance.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import UIKit

@MainActor
struct PagingDistance {
private let view: CollectionView
private let hasItemsBefore: Bool
Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/PageViewManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
@testable import Parchment
import XCTest

@MainActor
final class PageViewManagerTests: XCTestCase {
var dataSource: MockPageViewManagerDataSource!
var delegate: MockPageViewManagerDelegate!
Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/PagingCollectionViewLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import UIKit
import XCTest

@MainActor
final class PagingCollectionViewLayoutTests: XCTestCase {
private var window: UIWindow!
private var options: PagingOptions!
Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/PagingDistanceCenteredTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import Parchment
import XCTest

@MainActor
final class PagingDistanceCenteredTests: XCTestCase {
private var sizeCache: PagingSizeCache!

Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/PagingDistanceLeftTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import Parchment
import XCTest

@MainActor
final class PagingDistanceLeftTests: XCTestCase {
private var sizeCache: PagingSizeCache!

Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/PagingDistanceRightTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@testable import Parchment
import XCTest

@MainActor
final class PagingDistanceRightTests: XCTestCase {
private var sizeCache: PagingSizeCache!

Expand Down
1 change: 1 addition & 0 deletions ParchmentTests/Utilities/CreateDistance.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
@testable import Parchment

@MainActor
func createDistance(
bounds: CGRect = .zero,
contentSize: CGSize? = nil,
Expand Down

0 comments on commit 22b92d5

Please sign in to comment.