Skip to content

fix: swift 6 warnings #4005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions Amplify/Amplify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,83 @@
/// available at initialization.
///
/// - Tag: Amplify
public class Amplify {
public class Amplify: @unchecked Sendable {

/// If `true`, `configure()` has already been invoked, and subsequent calls to `configure` will throw a
/// ConfigurationError.amplifyAlreadyConfigured error.
///
/// - Tag: Amplify.isConfigured
static var isConfigured = false
private static let isConfiguredAtomic = AtomicValue<Bool>(initialValue: false)
static var isConfigured: Bool {
get { isConfiguredAtomic.get() }
set { isConfiguredAtomic.set(newValue) }
}

// Storage for the categories themselves, which will be instantiated during configuration, and cleared during reset.
// It is not supported to mutate these category properties. They are `var` to support the `reset()` method for
// ease of testing.
// All category properties are protected with AtomicValue for thread safety.

/// - Tag: Amplify.Analytics
public static internal(set) var Analytics = AnalyticsCategory()
private static let analyticsAtomic = AtomicValue<AnalyticsCategory>(initialValue: AnalyticsCategory())
public static internal(set) var Analytics: AnalyticsCategory {
get { analyticsAtomic.get() }
set { analyticsAtomic.set(newValue) }
}

/// - Tag: Amplify.API
public static internal(set) var API: APICategory = APICategory()
private static let apiAtomic = AtomicValue<APICategory>(initialValue: APICategory())
public static internal(set) var API: APICategory {
get { apiAtomic.get() }
set { apiAtomic.set(newValue) }
}

/// - Tag: Amplify.Auth
public static internal(set) var Auth = AuthCategory()
private static let authAtomic = AtomicValue<AuthCategory>(initialValue: AuthCategory())
public static internal(set) var Auth: AuthCategory {
get { authAtomic.get() }
set { authAtomic.set(newValue) }
}

/// - Tag: Amplify.DataStore
public static internal(set) var DataStore = DataStoreCategory()
private static let dataStoreAtomic = AtomicValue<DataStoreCategory>(initialValue: DataStoreCategory())
public static internal(set) var DataStore: DataStoreCategory {
get { dataStoreAtomic.get() }
set { dataStoreAtomic.set(newValue) }
}

/// - Tag: Amplify.Geo
public static internal(set) var Geo = GeoCategory()
private static let geoAtomic = AtomicValue<GeoCategory>(initialValue: GeoCategory())
public static internal(set) var Geo: GeoCategory {
get { geoAtomic.get() }
set { geoAtomic.set(newValue) }
}

/// - Tag: Amplify.Hub
public static internal(set) var Hub = HubCategory()
private static let hubAtomic = AtomicValue<HubCategory>(initialValue: HubCategory())
public static internal(set) var Hub: HubCategory {
get { hubAtomic.get() }
set { hubAtomic.set(newValue) }
}

/// - Tag: Amplify.Notifications
public static internal(set) var Notifications = NotificationsCategory()
private static let notificationsAtomic = AtomicValue<NotificationsCategory>(initialValue: NotificationsCategory())
public static internal(set) var Notifications: NotificationsCategory {
get { notificationsAtomic.get() }
set { notificationsAtomic.set(newValue) }
}

/// - Tag: Amplify.Predictions
public static internal(set) var Predictions = PredictionsCategory()
private static let predictionsAtomic = AtomicValue<PredictionsCategory>(initialValue: PredictionsCategory())
public static internal(set) var Predictions: PredictionsCategory {
get { predictionsAtomic.get() }
set { predictionsAtomic.set(newValue) }
}

/// - Tag: Amplify.Storage
public static internal(set) var Storage = StorageCategory()
private static let storageAtomic = AtomicValue<StorageCategory>(initialValue: StorageCategory())
public static internal(set) var Storage: StorageCategory {
get { storageAtomic.get() }
set { storageAtomic.set(newValue) }
}

/// Special case category. We protect this with an AtomicValue because it is used by reset()
/// methods during setup & teardown of tests
Expand All @@ -79,7 +118,7 @@
///
/// - Parameter plugin: The plugin to add
/// - Tag: Amplify.add_plugin
public static func add<P: Plugin>(plugin: P) throws {

Check warning on line 121 in Amplify/Amplify.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
log.debug("Adding plugin: \(plugin))")
switch plugin {
case let plugin as AnalyticsCategoryPlugin:
Expand Down
5 changes: 4 additions & 1 deletion Amplify/Categories/Auth/AuthCategory+UserBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import Foundation

extension AuthCategory: AuthCategoryUserBehavior {

public func getCurrentUser() async throws -> AuthUser {
/// Retrieve the current logged in user
///
/// - Returns: Current logged in user
public func getCurrentUser() async throws -> any AuthUser {
try await plugin.getCurrentUser()
}

Expand Down
5 changes: 3 additions & 2 deletions Amplify/Categories/Auth/AuthCategoryUserBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import Foundation

public protocol AuthCategoryUserBehavior: AnyObject {

/// Returns the currently logged in user.
/// Retrieve the current logged in user
///
func getCurrentUser() async throws -> AuthUser
/// - Returns: Current logged in user
func getCurrentUser() async throws -> any AuthUser

/// Fetch user attributes for the current user.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ public struct AuthCodeDeliveryDetails {
}

extension AuthCodeDeliveryDetails: Equatable {}

extension AuthCodeDeliveryDetails: Sendable {}
2 changes: 1 addition & 1 deletion Amplify/Categories/Auth/Models/AuthDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// Device used by the user to sign in
public protocol AuthDevice {
public protocol AuthDevice: Sendable {

/// Device id
var id: String { get }
Expand Down
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/AuthFactorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ public enum AuthFactorType: String {
case webAuthn
#endif
}

extension AuthFactorType: Sendable { }
2 changes: 1 addition & 1 deletion Amplify/Categories/Auth/Models/AuthSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/// Defines the auth session behavior
public protocol AuthSession {
public protocol AuthSession: Sendable {

/// True if the current user has signed in
///
Expand Down
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/AuthSignInStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ public enum AuthSignInStep {
}

extension AuthSignInStep: Equatable { }

extension AuthSignInStep: Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/AuthSignUpStep.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ public enum AuthSignUpStep {
/// Sign up is complete
case done
}

extension AuthSignUpStep: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ public enum AuthUpdateAttributeStep {
/// Update Attribute step is `done` when the update attribute flow is complete.
case done
}

extension AuthUpdateAttributeStep: Sendable { }
2 changes: 1 addition & 1 deletion Amplify/Categories/Auth/Models/AuthUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

/// Defines the protocol for an auth user
public protocol AuthUser {
public protocol AuthUser: Sendable {

/// User name of the auth user
var username: String { get }
Expand Down
4 changes: 4 additions & 0 deletions Amplify/Categories/Auth/Models/AuthUserAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ public enum AuthUserAttributeKey {
extension AuthUserAttributeKey: Hashable {}

extension AuthUserAttributeKey: Equatable {}

extension AuthUserAttributeKey: Sendable {}

extension AuthUserAttribute: Sendable {}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public struct AuthListWebAuthnCredentialsResult {
}
}

extension AuthListWebAuthnCredentialsResult: Sendable { }

/// Defines a WebAuthn credential
/// - Tag: AuthWebAuthnCredential
public protocol AuthWebAuthnCredential {
public protocol AuthWebAuthnCredential: Sendable {
/// The credential's ID
var credentialId: String { get }

Expand Down
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/DeliveryDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ public enum DeliveryDestination {
}

extension DeliveryDestination: Equatable { }

extension DeliveryDestination: Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/MFAType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ public enum MFAType: String {
/// Email Service linked with an email
case email
}

extension MFAType: Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Models/TOTPSetupDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ public struct TOTPSetupDetails {
}

extension TOTPSetupDetails: Equatable { }

extension TOTPSetupDetails: Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public extension AuthAssociateWebAuthnCredentialRequest {
}
}
}

extension AuthAssociateWebAuthnCredentialRequest.Options: @unchecked Sendable { }
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

// swiftlint:disable type_name

Check warning on line 10 in Amplify/Categories/Auth/Request/AuthAttributeResendConfirmationCodeRequest.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

The disabled 'type_name' rule should be re-enabled before the end of the file (blanket_disable_command)

/// Request for resending confirmation code that was generated for update attribute
public struct AuthAttributeResendConfirmationCodeRequest: AmplifyOperationRequest {
Expand Down Expand Up @@ -39,3 +39,5 @@
}
}
}

extension AuthAttributeResendConfirmationCodeRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ public extension AuthSendUserAttributeVerificationCodeRequest {
}
}
}

extension AuthSendUserAttributeVerificationCodeRequest.Options: @unchecked Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Request/AuthAutoSignInRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ public extension AuthAutoSignInRequest {
}
}
}

extension AuthAutoSignInRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ public extension AuthChangePasswordRequest {
}
}
}

extension AuthChangePasswordRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ public extension AuthConfirmResetPasswordRequest {
}
}
}

extension AuthConfirmResetPasswordRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ public extension AuthConfirmSignInRequest {
#endif
}
}

extension AuthConfirmSignInRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ public extension AuthConfirmSignUpRequest {
}
}
}

extension AuthConfirmSignUpRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ public extension AuthConfirmUserAttributeRequest {
}
}
}

extension AuthConfirmUserAttributeRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ public extension AuthDeleteWebAuthnCredentialRequest {
}
}
}

extension AuthDeleteWebAuthnCredentialRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ public extension AuthFetchDevicesRequest {
}
}
}

extension AuthFetchDevicesRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public extension AuthFetchSessionRequest {
}
}

extension AuthFetchSessionRequest.Options: @unchecked Sendable { }

extension AuthFetchSessionRequest.Options {
public static func forceRefresh() -> AuthFetchSessionRequest.Options {
return AuthFetchSessionRequest.Options(forceRefresh: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ public extension AuthFetchUserAttributesRequest {
}
}
}

extension AuthFetchUserAttributesRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ public extension AuthForgetDeviceRequest {
}
}
}

extension AuthForgetDeviceRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ public extension AuthListWebAuthnCredentialsRequest {
}
}
}

extension AuthListWebAuthnCredentialsRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ public extension AuthRememberDeviceRequest {
}
}
}

extension AuthRememberDeviceRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ public extension AuthResendSignUpCodeRequest {
}
}
}

extension AuthResendSignUpCodeRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ public extension AuthResetPasswordRequest {
}
}
}

extension AuthResetPasswordRequest.Options: @unchecked Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Request/AuthSignInRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ public extension AuthSignInRequest {
#endif
}
}

extension AuthSignInRequest.Options: @unchecked Sendable { }
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Request/AuthSignOutRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public extension AuthSignOutRequest {

}

extension AuthSignOutRequest.Options: @unchecked Sendable { }

#if os(iOS) || os(macOS) || os(visionOS)
extension AuthSignOutRequest.Options {
public static func presentationAnchor(_ anchor: AuthUIPresentationAnchor) -> AuthSignOutRequest.Options {
Expand Down
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Request/AuthSignUpRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ public extension AuthSignUpRequest {
}
}
}

extension AuthSignUpRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ public extension AuthUpdateUserAttributeRequest {
}
}
}

extension AuthUpdateUserAttributeRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ public extension AuthUpdateUserAttributesRequest {
}
}
}

extension AuthUpdateUserAttributesRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ public extension AuthWebUISignInRequest {
}
}
}

extension AuthWebUISignInRequest.Options: @unchecked Sendable { }
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ public extension VerifyTOTPSetupRequest {
}
}
}

extension VerifyTOTPSetupRequest.Options: @unchecked Sendable { }
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public struct AuthResetPasswordResult {

extension AuthResetPasswordResult: Equatable {}

extension AuthResetPasswordResult: Sendable {}

/// The next step in Auth.resetPassword api
public enum AuthResetPasswordStep {

Expand All @@ -42,3 +44,5 @@ public enum AuthResetPasswordStep {
}

extension AuthResetPasswordStep: Equatable {}

extension AuthResetPasswordStep: Sendable {}
2 changes: 2 additions & 0 deletions Amplify/Categories/Auth/Result/AuthSignInResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ public struct AuthSignInResult {
self.nextStep = nextStep
}
}

extension AuthSignInResult: Sendable { }
Loading
Loading