diff --git a/docs/main/ios/spm.md b/docs/main/ios/spm.md index af20d349..e27dbd2e 100644 --- a/docs/main/ios/spm.md +++ b/docs/main/ios/spm.md @@ -3,6 +3,7 @@ title: Swift Package Manager description: SPM Basics contributors: - giralte-ionic + - markemer slug: /ios/spm --- @@ -14,7 +15,7 @@ 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: @@ -22,13 +23,12 @@ When a Capacitor project is using SPM we use a 'Base SPM' package that will serv 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`:  - Now we want to add the iOS platform to our project: `npm install @capacitor/ios` @@ -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. @@ -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 + +### 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: + + + +Highlight App, and Select the Package Dependencies tab, and on this page press the + symbol to add a dependency: + + + +You should see something similar to the below - select Add Local... from the dialog: + + + +Select CapApp-SPM in this dialog and click Add Package: + + + +Click Add Package again when this screen shows up: + + + +When you are done, you should see a screen like this. At this point you're done and can build and work as normal: + + ### Converting existing plugins to SPM diff --git a/package.json b/package.json index 814343a1..ac89266c 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,5 @@ "devDependencies": { "@ionic/prettier-config": "^4.0.0", "prettier": "^3.1.1" - }, - "volta": { - "node": ">=18.0", - "npm": "8.15.0" } } diff --git a/static/img/spm/xcode-step-1.png b/static/img/spm/xcode-step-1.png new file mode 100644 index 00000000..00bb0c6e Binary files /dev/null and b/static/img/spm/xcode-step-1.png differ diff --git a/static/img/spm/xcode-step-2.png b/static/img/spm/xcode-step-2.png new file mode 100644 index 00000000..4b54c50a Binary files /dev/null and b/static/img/spm/xcode-step-2.png differ diff --git a/static/img/spm/xcode-step-3.png b/static/img/spm/xcode-step-3.png new file mode 100644 index 00000000..1b2dda94 Binary files /dev/null and b/static/img/spm/xcode-step-3.png differ diff --git a/static/img/spm/xcode-step-4.png b/static/img/spm/xcode-step-4.png new file mode 100644 index 00000000..e7c42f57 Binary files /dev/null and b/static/img/spm/xcode-step-4.png differ diff --git a/static/img/spm/xcode-step-5.png b/static/img/spm/xcode-step-5.png new file mode 100644 index 00000000..c021e50a Binary files /dev/null and b/static/img/spm/xcode-step-5.png differ diff --git a/static/img/spm/xcode-step-6.png b/static/img/spm/xcode-step-6.png new file mode 100644 index 00000000..31a97a96 Binary files /dev/null and b/static/img/spm/xcode-step-6.png differ