Upgrade guide
As of v2, Amplify Library iOS is now Amplify Library for Swift. Amplify Library for Swift supports iOS 13+ and macOS 10.15+, and ships with APIs that leverage Swift Concurrency (async/await) to return values. There are a few things you need to know if you are upgrading to this latest version.
What's changed
We have re-written our APIs to support idiomatic Swift features including structured concurrency and combine support. We have also changed how you access the underlying SDK (keep in mind that the AWS SDK for Swift is still in Developer Preview).
The Predictions APIs do not currently have an upgrade plan. We will update this guide as soon as they do.
Using the new Swift features with Amplify APIs
Structured Concurrency (async/await pattern)
All our APIs have been refactored to follow the async/await structured concurrency pattern. The following is an comparison of how you would implement Sign-In for your authentication flows:
Implementing Sign-In in Amplify Library iOS / v1
Previously, you would use a callback API like so:
func signIn(username: String, password: String) { Amplify.Auth.signIn(username: username, password: password) { result in switch result { case .success: print("Sign in succeeded") case .failure(let error): print("Sign in failed \(error)") } }}
Implementing Sign-In in Amplify Library for Swift / v2
Now with Amplify Library for Swift, you would use the async/await pattern like so:
func signIn(username: String, password: String) async throws { let signInResult = try await Amplify.Auth.signIn( username: username, password: password ) if signInResult.isSignedIn { print("Sign in succeeded") }}
Combine support
Amplify for Swift supports converting the async/await apis to Combine publishers. For more details, check out the guide to using Combine with Amplify.
Escape Hatches
Amplify Library for Swift, also changes the way you access the underlying SDK. Now you have access to the AWS SDK for Swift. The following is an example on how you would SDK calls with Amplify Library for Swift:
import AWSPinpointAnalyticsPlugin
do { // Retrieve the reference to AWSPinpointAnalyticsPlugin let plugin = try Amplify.Analytics.getPlugin(for: "awsPinpointAnalyticsPlugin") guard let analyticsPlugin = plugin as? AWSPinpointAnalyticsPlugin else { return } // Retrieve the reference to PinpointClientProtocol from AWS SDK for Swift let pinpointClient = analyticsPlugin.getEscapeHatch()
// Make requests using pinpointClient... // ...} catch { print("Get escape hatch failed with error - \(error)")}