diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate+Controller.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate+Controller.swift index 14d76d57..d1966212 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate+Controller.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate+Controller.swift @@ -201,7 +201,7 @@ extension ApplePayAuthorizationDelegate: PKPaymentAuthorizationControllerDelegat // Taxes may become pending again fail to resolve despite updating within the didUpdatePaymentMethod // So we retry one time to see if the error clears on retry - _ = try await Task.retrying(priority: nil, maxRetryCount: 1) { + _ = try await Task.retrying(priority: nil, maxRetryCount: 1) { @MainActor in try await self.controller.storefront.cartPaymentUpdate( id: cartID, totalAmount: totalAmount, @@ -227,7 +227,9 @@ extension ApplePayAuthorizationDelegate: PKPaymentAuthorizationControllerDelegat ShopifyAcceleratedCheckouts.logger.debug("paymentAuthorizationControllerDidFinish, state: \(state)") controller.dismiss { - Task { try? await self.transition(to: .completed) } + Task { @MainActor in + try? await self.transition(to: .completed) + } } } diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate.swift index 1b9234db..1349e601 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegate.swift @@ -18,6 +18,7 @@ extension PKPaymentAuthorizationController: PaymentAuthorizationController {} typealias PKAuthorizationControllerFactory = (PKPaymentRequest) -> PaymentAuthorizationController @available(iOS 16.0, *) +@MainActor class ApplePayAuthorizationDelegate: NSObject, ObservableObject { let configuration: ApplePayConfigurationWrapper let abortError = ShopifyAcceleratedCheckouts.Error.invariant(expected: "cart") @@ -150,7 +151,7 @@ class ApplePayAuthorizationDelegate: NSObject, ObservableObject { break default: let cartID = try pkEncoder.cartID.get() - try? await _Concurrency.Task.retrying(clock: clock) { + try? await _Concurrency.Task.retrying(clock: clock) { @MainActor in try await self.controller.storefront.cartRemovePersonalData(id: cartID) }.value diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayButton.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayButton.swift index e529fe4e..ed51aeca 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayButton.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayButton.swift @@ -100,6 +100,7 @@ struct ApplePayButton: View { /// This is an internal view to allow Environment injection of the shared configuration app wide @available(iOS 16.0, *) @available(macOS, unavailable) +@MainActor struct Internal_ApplePayButton: View { private let label: PayWithApplePayButtonLabel private let style: PayWithApplePayButtonStyle @@ -134,7 +135,7 @@ struct Internal_ApplePayButton: View { buttonType: label.pkPaymentButtonType, buttonStyle: style.pkPaymentButtonStyle, cornerRadius: cornerRadius ?? 8, - action: { Task { await controller.onPress() } } + action: { Task { @MainActor in await controller.onPress() } } ) .id("\(colorScheme)-\(style.pkPaymentButtonStyle.rawValue)") .frame(height: 48) diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayViewController.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayViewController.swift index 9d9225aa..a231e878 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayViewController.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ApplePay/ApplePayViewController.swift @@ -3,6 +3,7 @@ import ShopifyCheckoutKit import SwiftUI @available(iOS 16.0, *) +@MainActor protocol PayController: AnyObject { var cart: StorefrontAPI.Types.Cart? { get set } var storefront: StorefrontAPIProtocol { get set } @@ -12,6 +13,7 @@ protocol PayController: AnyObject { } @available(iOS 16.0, *) +@MainActor class ApplePayViewController: WalletController, PayController { @Published var paymentController: PKPaymentAuthorizationController? @@ -73,7 +75,7 @@ class ApplePayViewController: WalletController, PayController { self.client = LifecycleObservingClient(base: client, onComplete: { [weak self] in guard let self else { return } - Task { + Task { @MainActor in try? await self.authorizationDelegate.transition(to: .completed) } }) @@ -90,9 +92,7 @@ class ApplePayViewController: WalletController, PayController { ShopifyAcceleratedCheckouts.logger.error( "[startPayment] Failed to setup cart: \(error)" ) - Task { @MainActor in - self.onCheckoutFail?(.sdkError(underlying: error)) - } + onCheckoutFail?(.sdkError(underlying: error)) } do { diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayButton.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayButton.swift index 229721b8..71c4533c 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayButton.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayButton.swift @@ -49,6 +49,7 @@ internal struct ShopPayButton: View { /// Internal_ wrapper component allows `ShopifyAcceleratedCheckouts.Configuration` to be /// DI into ShopPayViewController at init, avoiding optionality checks through ViewController @available(iOS 16.0, *) +@MainActor internal struct Internal_ShopPayButton: View { private var controller: ShopPayViewController private let cornerRadius: CGFloat? @@ -72,7 +73,7 @@ internal struct Internal_ShopPayButton: View { var body: some View { Button( action: { - Task { await controller.onPress() } + Task { @MainActor in await controller.onPress() } }, label: { HStack { diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayViewController.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayViewController.swift index ae096be4..8bc19170 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayViewController.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/ShopPay/ShopPayViewController.swift @@ -2,6 +2,7 @@ import ShopifyCheckoutKit import SwiftUI @available(iOS 16.0, *) +@MainActor class ShopPayViewController: WalletController { var eventHandlers: EventHandlers var client: (any CheckoutCommunicationProtocol)? diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/WalletController.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/WalletController.swift index 72544f2e..128d7180 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/WalletController.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/WalletController.swift @@ -2,6 +2,7 @@ import ShopifyCheckoutKit import SwiftUI @available(iOS 16.0, *) +@MainActor class WalletController: ObservableObject { @Published var identifier: CheckoutIdentifier @Published var storefront: StorefrontAPIProtocol @@ -34,7 +35,6 @@ class WalletController: ObservableObject { } } - @MainActor func present(url: URL, client: (any CheckoutCommunicationProtocol)?) async throws { guard let topViewController = getTopViewController() else { throw ShopifyAcceleratedCheckouts.Error.invariant(expected: "topViewController") @@ -47,7 +47,6 @@ class WalletController: ObservableObject { ) } - @MainActor func getTopViewController() -> UIViewController? { guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = windowScene.windows.first diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayCallbackTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayCallbackTests.swift index cc803731..44c41d5c 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayCallbackTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayCallbackTests.swift @@ -3,6 +3,7 @@ import XCTest @available(iOS 17.0, *) +@MainActor final class ApplePayCallbackTests: XCTestCase { // MARK: - Properties diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayViewControllerTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayViewControllerTests.swift index 5f3576c0..f0026e95 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayViewControllerTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayViewControllerTests.swift @@ -4,6 +4,7 @@ import UIKit import XCTest @available(iOS 17.0, *) +@MainActor class ApplePayViewControllerTests: XCTestCase { var viewController: MockApplePayViewController! var mockConfiguration: ApplePayConfigurationWrapper! diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayButtonTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayButtonTests.swift index fe9d460f..a1d8c45f 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayButtonTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayButtonTests.swift @@ -4,6 +4,7 @@ import ViewInspector import XCTest @available(iOS 17.0, *) +@MainActor class ShopPayButtonTests: XCTestCase { // MARK: - Test Setup diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayCallbackTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayCallbackTests.swift index d8a7dd74..2b3d56e1 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayCallbackTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayCallbackTests.swift @@ -3,6 +3,7 @@ import XCTest @available(iOS 17.0, *) +@MainActor final class ShopPayCallbackTests: XCTestCase { // MARK: - Properties diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayViewControllerTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayViewControllerTests.swift index d4d4adf8..da22fb07 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayViewControllerTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ShopPay/ShopPayViewControllerTests.swift @@ -3,8 +3,7 @@ import ShopifyCheckoutKit import XCTest @available(iOS 16.0, *) - -@available(iOS 16.0, *) +@MainActor final class ShopPayViewControllerTests: XCTestCase { var viewController: MockShopPayViewController! var mockConfiguration: ShopifyAcceleratedCheckouts.Configuration! diff --git a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/WalletControllerTests.swift b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/WalletControllerTests.swift index 9bb34b68..cf98df31 100644 --- a/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/WalletControllerTests.swift +++ b/platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/WalletControllerTests.swift @@ -4,6 +4,7 @@ import UIKit import XCTest @available(iOS 16.0, *) +@MainActor final class WalletControllerTests: XCTestCase { var mockStorefront: TestStorefrontAPI! var controller: MockWalletController!