Skip to content

Instantly share code, notes, and snippets.

@stefang
Last active May 16, 2025 09:11
Show Gist options
  • Select an option

  • Save stefang/6e8302b707d420f7e110669d3f83315e to your computer and use it in GitHub Desktop.

Select an option

Save stefang/6e8302b707d420f7e110669d3f83315e to your computer and use it in GitHub Desktop.

iOS only Capacitor Plugin using Swift Package Manager

This took me way longer than it should have to work this out as I'm not a iOS developer so this may help someone. I was trying to make a wrapper plugin for OSCKit so I could use it in my Ionic / Capacitor App.

As per usual (~May 2025)

npm init @capacitor/plugin
cd capacitor-osckit
npm install    

Remove Android

npm uninstall @capacitor/android

Delete default example-app and android folder

rm -r example-app
rm -r android

Create new example-app

npm init @capacitor/app@latest  
cd example-app  
npm install @capacitor/ios
npm run build  

This is the key.. Add iOS but using the SPM package manager. This needs to be done here but also in whatever app you'll be using the plugin in.

npx cap add ios --packagemanager SPM
npm install

Then add parent plug in as a npm package

npm install ../      

And sync / open in Xcode

npx cap sync            
npx cap open ios     

Then add the package to the Package.swift file

// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "CapacitorOsckit",
    platforms: [.iOS(.v14)],
    products: [
        .library(
            name: "CapacitorOsckit",
            targets: ["CapacitorOSCKitPlugin"])
    ],
    dependencies: [
        .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0"),
        .package(url: "https://github.com/orchetect/OSCKit", from: "1.2.1"),

    ],
    targets: [
        .target(
            name: "CapacitorOSCKitPlugin",
            dependencies: [
                .product(name: "Capacitor", package: "capacitor-swift-pm"),
                .product(name: "Cordova", package: "capacitor-swift-pm"),
                .product(name: "OSCKit", package: "OSCKit")
            ],
            path: "ios/Sources/CapacitorOSCKitPlugin"),
        .testTarget(
            name: "CapacitorOSCKitPluginTests",
            dependencies: ["CapacitorOSCKitPlugin"],
            path: "ios/Tests/CapacitorOSCKitPluginTests")
    ]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment