Page updated Nov 3, 2023

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:

1func signIn(username: String, password: String) {
2 Amplify.Auth.signIn(username: username, password: password) { result in
3 switch result {
4 case .success:
5 print("Sign in succeeded")
6 case .failure(let error):
7 print("Sign in failed \(error)")
8 }
9 }
10}

Implementing Sign-In in Amplify Library for Swift / v2

Now with Amplify Library for Swift, you would use the async/await pattern like so:

1func signIn(username: String, password: String) async throws {
2 let signInResult = try await Amplify.Auth.signIn(
3 username: username,
4 password: password
5 )
6 if signInResult.isSignedIn {
7 print("Sign in succeeded")
8 }
9}

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:

1import AWSPinpointAnalyticsPlugin
2
3do {
4 // Retrieve the reference to AWSPinpointAnalyticsPlugin
5 let plugin = try Amplify.Analytics.getPlugin(for: "awsPinpointAnalyticsPlugin")
6 guard let analyticsPlugin = plugin as? AWSPinpointAnalyticsPlugin else {
7 return
8 }
9
10 // Retrieve the reference to PinpointClientProtocol from AWS SDK for Swift
11 let pinpointClient = analyticsPlugin.getEscapeHatch()
12
13 // Make requests using pinpointClient...
14 // ...
15} catch {
16 print("Get escape hatch failed with error - \(error)")
17}

Note: While the Amplify Library for Swift is production ready, please note that the underlying AWS SDK for Swift is currently in Developer Preview, and is not yet intended for production workloads. You can read about the SDK's ongoing development in this additional documentation.