amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

`Amplify.Auth` does not `Sendable` conform, will this be solved until release of Swift 6?

Open tscholze opened this issue 1 year ago • 10 comments

Describe the bug

Regarding using Amplify.Auth in SwiftUI with Swift 5.10, there will be warnings over all the place because some of the Auth's classes, protocols, etc. are not actor'ized.

This will lead to compilation errors in Swift 6 but currently there will be a lot of warnings that may break CI checks for warning threshold.

If this can be solved in the client app, please let me know.

Steps To Reproduce

Steps to reproduce the behavior:
1. Create a SwiftUI project
2. Embed `2.36.0` of Amplify iOS SDK
3. Use methods like `_ = await Amplify.Auth.signOut()`
4. See warnings (Swift 5) or errors (Swift 6)

> Non-sendable type 'any AuthSignOutResult' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary

Expected behavior

Amplify.Auth works fine with SwiftUI, actors

Amplify Framework Version

2.36.0

Amplify Categories

Auth

Dependency manager

Swift PM

Swift version

5.10

CLI version

not installed - iOS only

Xcode version

Version 15.4 (15F31d)

Relevant log output

<details>
<summary>Log Messages</summary>
No logs
</details>

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 17

Device

all

Specific to simulators

no

Additional context

No response

tscholze avatar Aug 22 '24 12:08 tscholze

Thanks for raising the concern. Our team will look into prioritizing this request.

harsh62 avatar Aug 22 '24 13:08 harsh62

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

github-actions[bot] avatar Aug 22 '24 13:08 github-actions[bot]

Reference to class property 'Auth' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6 is also shown from a line such as

let result = await Amplify.Auth.signOut()

MMise avatar Sep 05 '24 07:09 MMise

Reference to class property 'Auth' is not concurrency-safe because it involves shared mutable state; this is an error in Swift 6 is also shown from a line such as

let result = await Amplify.Auth.signOut()

Hi @MMise , I tested with a sample app using Xcode Version 15.4 (15F31d) but couldn't reproduce the warning message. Which version of Xcode are you using?

5d avatar Sep 05 '24 17:09 5d

Is there any update on this issue?

@5d did you enable the Swift 6 warnings? :)

tscholze avatar Oct 07 '24 09:10 tscholze

@5d I am using Xcode 15.3 with Strict Concurrency Checking set to Complete

MMise avatar Oct 07 '24 09:10 MMise

Thank you for your patience - our team will take a look and post updates here.

thisisabhash avatar Oct 09 '24 16:10 thisisabhash

Has there been any progress on this?

dcutting-neurode avatar Mar 18 '25 01:03 dcutting-neurode

I do not have any updates at the moment. I'll re-engage the team to take a look.

tylerjroach avatar Mar 26 '25 13:03 tylerjroach

The team is still trying to see if this could be pulled into the roadmap. For now, following are our recommendations:

  1. Disable Strict Concurrency
// Build Settings → Swift Compiler - Language
// Set "Strict Concurrency Checking" to "Minimal" or "Targeted"
  1. Suppress Specific Warnings

Using Compiler Directives:

// Suppress concurrency warnings for specific code blocks
#if compiler(>=5.10)
@preconcurrency import Amplify
#else
import Amplify
#endif

Wrap Problematic Code:

// For non-sendable types crossing actor boundaries
Task { @MainActor in
    // Keep operations on main actor to avoid boundary crossing
    let options = AuthSignUpRequest.Options(userAttributes: attributes)
    let result = try await Amplify.Auth.signUp(username: username, password: password, options: options)
}
  1. Type Erasure Workaround

For Protocol Usage Issues:

// Instead of: let user: AuthUser = ...
// Use type erasure:
let user = try await Amplify.Auth.getCurrentUser()
// Swift will infer the type without explicit protocol annotation

For Function Parameters:

// Instead of: func processUser(_ user: AuthUser)
func processUser(_ user: some AuthUser) {
    // Use 'some' instead of 'any' where possible
}

harsh62 avatar Jun 12 '25 05:06 harsh62

We have released 2.51.0 with a bunch of fixes to resolve the Swift 6 build warnings: https://github.com/aws-amplify/amplify-swift/releases/tag/2.51.0

Please let us know if this is still an issue.

thisisabhash avatar Sep 16 '25 18:09 thisisabhash

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

github-actions[bot] avatar Oct 28 '25 17:10 github-actions[bot]