Skip to content

docs: SPM Migration Docs #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions docs/main/ios/spm.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Swift Package Manager
description: SPM Basics
contributors:
- giralte-ionic
- markemer
slug: /ios/spm
---

Expand All @@ -14,21 +15,20 @@ Since Capacitor 6, you can choose between using CocoaPods or Swift Package Manag

We've tried our best to make sure you don't have to change much about how you work with Capacitor to use SPM, but there are a few things to understand.

### How it works
## How it works

When a Capacitor project is using SPM we use a 'Base SPM' package that will serve as the place that references all of your projects dependencies:

![Base SPM Picture](../../../static/img/v6/docs/ios/spm/base-spm.png)

The Capacitor CLI will modify the CapAPP-SPM package when you sync new plugins. It is important you do not touch the contents here because the CLI can and will change things.

### Using SPM in a new Capacitor project
## Using SPM in a new Capacitor project

First we'll start with our normal `npm init @capacitor/app@latest`:

![Demo Step 1](../../../static/img/v6/docs/ios/spm/demo-step1.png)


Now we want to add the iOS platform to our project:

`npm install @capacitor/ios`
Expand All @@ -45,7 +45,7 @@ Now you can use `npx cap open ios` to open the iOS project and run your app from

---

### Add and use a Capactior Plugin with SPM
### Add and use a Capacitor Plugin with SPM

So let's add a plugin to this project and do something with that plugin.

Expand All @@ -59,7 +59,45 @@ Then let's sync the web app. This will add the App plugin SPM to the iOS project

You can now use the App plugin normally.

<em>More details coming soon</em>
## Using SPM in an existing Capacitor Project

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a first section could mention the possibility of removing ios folder and adding it back with npx cap add ios --packagemanager SPM in case the user didn't do any custom changes to the project, since that's the "easiest" migration and requires no manual steps.

### Using our migration tool

The Capacitor CLI has a command to help migrate from CocoaPods to Swift Package Manager. However, one manual step is still required. In addition, projects with Cordova plugins will not be migrated correctly and neither will projects that use plugins that do not have SPM versions available.

To start, run `npx cap migrate-to-spm` in the root of your project.

This tool will:
- Run `pod deintegrate` removing CocoaPods
- Delete the `Podfile`, `App.xcworkspace`, and `Podfile.lock`
- Create a `CapApp-SPM` directory with the needed files
- Generate a `Package.swift` from your plugins, and warn you if any can't included.

After this is run, run a `npx cap sync` again.

Then run `npx cap open ios` and you should see something similar to this:

![Migrate Step 1](../../../static/img/spm/xcode-step-1.png)

Highlight App, and Select the Package Dependencies tab, and on this page press the + symbol to add a dependency:

![Migrate Step 2](../../../static/img/spm/xcode-step-2.png)

You should see something similar to the below - select Add Local... from the dialog:

![Migrate Step 3](../../../static/img/spm/xcode-step-3.png)

Select CapApp-SPM in this dialog and click Add Package:

![Migrate Step 4](../../../static/img/spm/xcode-step-4.png)

Click Add Package again when this screen shows up:

![Migrate Step 5](../../../static/img/spm/xcode-step-5.png)

When you are done, you should see a screen like this. At this point you're done and can build and work as normal:

![Migrate Step 6](../../../static/img/spm/xcode-step-6.png)

### Converting existing plugins to SPM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ticket also mentioned

Converting existing plugins to SPM- this section says "more coming soon"; it should probably be filled out

But this section is unchanged, should be updated too


Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,5 @@
"devDependencies": {
"@ionic/prettier-config": "^4.0.0",
"prettier": "^3.1.1"
},
"volta": {
"node": ">=18.0",
"npm": "8.15.0"
}
}
Binary file added static/img/spm/xcode-step-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/spm/xcode-step-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/spm/xcode-step-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/spm/xcode-step-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/spm/xcode-step-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/spm/xcode-step-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.