Skip to content

Commit 1a1aa07

Browse files
authored
chore: Add support docs for Swift Package Manager (#1147)
[skip ci]
1 parent db3c2f1 commit 1a1aa07

7 files changed

+96
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Features
66

7-
- Update dependencies to support installation via Swift Package Manager (#1146)
7+
- Amplify iOS can now be installed via Swift Package Manager. See the [README](https://github.com/aws-amplify/amplify-ios/blob/main/README.md) for full details. (#1146)
88

99
## 1.7.2 (2021-04-02)
1010

README.md

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,72 @@ This library is licensed under the Apache 2.0 License.
4141

4242
Amplify requires Xcode 11.4 or higher to build.
4343

44-
### CocoaPods
45-
4644
| :information_source: For more detailed instructions, follow the getting started guides in our [documentation site](https://docs.amplify.aws/lib/q/platform/ios) |
4745
|-------------------------------------------------|
4846

47+
### Swift Package Manager
48+
49+
1. Swift Package Manager is distributed with Xcode. To start adding the Amplify Libraries to your iOS project, open your project in Xcode and select **File > Swift Packages > Add Package Dependency**.
50+
51+
![Add package dependency](readme-images/spm-setup-01-add-package-dependency.png)
52+
53+
1. Enter the Amplify iOS GitHub repo URL (`https://github.com/aws-amplify/amplify-ios`) into the search bar and click **Next**.
54+
55+
![Search for repo](readme-images/spm-setup-02-search-amplify-repo.png)
56+
57+
1. You'll see the Amplify iOS repository rules for which version of Amplify you want Swift Package Manager to install. Choose the first rule, **Version**, as it will use the latest compatible version of the dependency that can be detected from the `main` branch, then click **Next**.
58+
59+
![Dependency version options](readme-images/spm-setup-03-dependency-version-options.png)
60+
61+
1. Choose which of the libraries you want added to your project. Always select the **Amplify** library. The "Plugin" to install depends on which categories you are using:
62+
63+
- API: **AWSAPIPlugin**
64+
- Analytics: **AWSPinpointAnalyticsPlugin**
65+
- Auth: **AWSCognitoAuthPlugin**
66+
- DataStore: **AWSDataStorePlugin**
67+
- Storage: **AWSS3StoragePlugin**
68+
69+
_Note: AWSPredictionsPlugin is not currently supported through Swift Package Manager due to different minimum iOS version requirements. Support for this will eventually be added._
70+
71+
![Select dependencies](readme-images/spm-setup-04-select-dependencies.png)
72+
73+
Select all that are appropriate, then click **Finish**.
74+
75+
You can always go back and modify which SPM packages are included in your project by opening the Swift Packages tab for your project: Click on the Project file in the Xcode navigator, then click on your project's icon, then select the **Swift Packages** tab.
76+
77+
1. In your app code, explicitly import a plugin when you need to add a plugin to Amplify, access plugin options, or access a category escape hatch.
78+
79+
```swift
80+
import Amplify
81+
import AWSAPIPlugin
82+
import AWSDataStorePlugin
83+
84+
// ... later
85+
86+
func initializeAmplify() {
87+
do {
88+
try Amplify.add(AWSAPIPlugin())
89+
// and so on ...
90+
} catch {
91+
assert(false, "Error initializing Amplify: \(error)")
92+
}
93+
}
94+
```
95+
96+
If you're just accessing Amplify category APIs (e.g., `Auth.signIn()` or `Storage.uploadFile()`), you only need to import Amplify:
97+
98+
```swift
99+
import Amplify
100+
101+
// ... later
102+
103+
func doUpload() {
104+
Amplify.Storage.uploadFile(...)
105+
}
106+
```
107+
108+
### CocoaPods
109+
49110
1. Amplify for iOS is available through [CocoaPods](http://cocoapods.org). If you have not installed CocoaPods, install CocoaPods by running the command:
50111
```
51112
$ gem install cocoapods
@@ -59,7 +120,7 @@ Amplify requires Xcode 11.4 or higher to build.
59120
$ pod setup
60121
```
61122

62-
2. In your project directory (the directory where your `*.xcodeproj` file is), type `pod init` and open the Podfile that was created. Add the `Amplify` pod and any plugins you would like to use. Below is an example of what a podfile might look like if you were going to use the Predictions plugin.
123+
1. In your project directory (the directory where your `*.xcodeproj` file is), type `pod init` and open the Podfile that was created. Add the `Amplify` pod and any plugins you would like to use. Below is an example of what a podfile might look like if you were going to use the Predictions plugin.
63124
```ruby
64125
source 'https://github.com/CocoaPods/Specs.git'
65126

@@ -74,21 +135,47 @@ Amplify requires Xcode 11.4 or higher to build.
74135
end
75136
```
76137

77-
3. Then run the following command:
138+
1. Then run the following command:
78139
```
79140
$ pod install
80141
```
81-
4. Open up `*.xcworkspace` with Xcode and start using Amplify.
142+
1. Open up `*.xcworkspace` with Xcode and start using Amplify.
82143

83144
![image](readme-images/cocoapods-setup-02.png?raw=true)
84145

85146
**Note**: Do **NOT** use `*.xcodeproj`. If you open up a project file instead of a workspace, you will receive an error.
86147

87-
### Swift Package Manager (SPM)
148+
1. In your app code, import `AmplifyPlugins` when you need to add a plugin to Amplify, access plugin options, or access a category escape hatch.
88149

89-
Support for SPM coming soon. Follow [#90](https://github.com/aws-amplify/amplify-ios/issues/90) for updates.
150+
```swift
151+
import Amplify
152+
import AmplifyPlugins
153+
154+
// ... later
155+
156+
func initializeAmplify() {
157+
do {
158+
try Amplify.add(AWSAPIPlugin())
159+
// and so on ...
160+
} catch {
161+
assert(false, "Error initializing Amplify: \(error)")
162+
}
163+
}
164+
```
165+
166+
If you're just accessing Amplify category APIs (e.g., `Auth.signIn()` or `Storage.uploadFile()`), you only need to import Amplify:
167+
168+
```swift
169+
import Amplify
170+
171+
// ... later
172+
173+
func doUpload() {
174+
Amplify.Storage.uploadFile(...)
175+
}
176+
```
90177

91-
### Development Pods
178+
**Development Pods**
92179

93180
You can manually install the library by cloning this repo and creating a Podfile that references your local clone of it like below:
94181

77.2 KB
Loading
84.6 KB
Loading
27.4 KB
Loading
34.6 KB
Loading
75.1 KB
Loading

0 commit comments

Comments
 (0)