|
1 |
| -# Upgrade Guide: Amplify Library for Swift |
2 |
| - |
3 |
| -As part of the latest version of Amplify Library for Swift, we have re-written our APIs to support idiomatic Swift features. |
4 |
| - |
5 |
| -### Structured Concurrency (async/await pattern) |
6 |
| - |
7 |
| -All our APIs have been refactored to follow the async/await structured concurrency pattern. The following is an example of how you would implement Sign-In for your authentication flows: |
8 |
| - |
9 |
| -v1 - Callback API |
10 |
| - |
11 |
| -```swift |
12 |
| -func signIn(username: String, password: String) { |
13 |
| - Amplify.Auth.signIn(username: username, password: password) { result in |
14 |
| - switch result { |
15 |
| - case .success: |
16 |
| - print("Sign in succeeded") |
17 |
| - case .failure(let error): |
18 |
| - print("Sign in failed \(error)") |
19 |
| - } |
20 |
| - } |
21 |
| -} |
22 |
| -``` |
23 |
| - |
24 |
| -v2 - Async/Await |
25 |
| - |
26 |
| -```swift |
27 |
| -func signIn(username: String, password: String) async throws { |
28 |
| - let signInResult = try await Amplify.Auth.signIn( |
29 |
| - username: username, |
30 |
| - password: password |
31 |
| - ) |
32 |
| - if signInResult.isSignedIn { |
33 |
| - print("Sign in succeeded") |
34 |
| - } |
35 |
| -} |
36 |
| -``` |
37 |
| - |
38 |
| -### Combine support |
39 |
| - |
40 |
| -Support for combine apis was also changed in the v2. You can read more about the changes in the dedicated doc here - |
41 |
| -https://github.com/aws-amplify/amplify-swift/blob/main/README-combine-support.md |
42 |
| - |
43 |
| -For detailed definitions of all the Amplify features available in this version, please refer to [our latest v2 documentation](https://docs.amplify.aws/lib/q/platform/ios/). |
44 |
| - |
45 |
| -### Predictions |
46 |
| - |
47 |
| -Currently, we do not have an upgrade plan for predictions APIs. We will keep this guide updated when we have more information on this. |
48 |
| - |
49 |
| -### Escape Hatch |
50 |
| - |
51 |
| -With Amplify Library for Swift, we have also changed the way you access the underlying SDK. You now have access to the AWS SDK for Swift and the following is an example on how you would SDK calls via Amplify. |
52 |
| - |
53 |
| -```swift |
54 |
| -import AWSPinpointAnalyticsPlugin |
55 |
| - |
56 |
| -do { |
57 |
| - // Retrieve the reference to AWSPinpointAnalyticsPlugin |
58 |
| - let plugin = try Amplify.Analytics.getPlugin(for: "awsPinpointAnalyticsPlugin") |
59 |
| - guard let analyticsPlugin = plugin as? AWSPinpointAnalyticsPlugin else { |
60 |
| - return |
61 |
| - } |
62 |
| - |
63 |
| - // Retrieve the reference to PinpointClientProtocol from AWS SDK for Swift |
64 |
| - let pinpointClient = analyticsPlugin.getEscapeHatch() |
65 |
| - |
66 |
| - // Make requests using pinpointClient... |
67 |
| - // ... |
68 |
| -} catch { |
69 |
| - print("Get escape hatch failed with error - \(error)") |
70 |
| -} |
71 |
| -``` |
72 |
| - |
73 |
| -**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. [Here is additional reading material](https://github.com/awslabs/aws-sdk-swift/blob/main/docs/stability.md) on the stability of the SDK. |
| 1 | +The Upgrade Guide has moved to [Project Setup > Upgrade Guide](https://docs.amplify.aws/lib/project-setup/upgrade-guide/q/platform/ios/). |
0 commit comments