I want to write an internal NPM to work with Firebase Firestore, for this I need to use the Firebase SDK via SPM.
I add dependency in Package.swift
(example below)
but I can’t use it in code.
My Package.swift
code
import PackageDescription
let package = Package(
name: "FCM",
platforms: [.iOS(.v16)],
products: [
.library(
name: "FCM",
targets: ["FCM"]),
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk", .upToNextMinor(from: "9.6.0")),
],
targets: [
.target(
name: "FCM",
dependencies: [
]),
.testTarget(
name: "FCMTest",
dependencies: ["FCMTest"]),
]
)
2
Answers
With
dependencies: [.package(url: ...)]
you are just saying that yourPackage
will depend on theFirebase
package.To use a dependency package in one of your targets, you need to specify what product your target will need to depend on.
In your target add the
dependencies: []
attribute and define the firebase framework that you need by using.product(name: , package: )
:Useful links:
Guiseppe’s answer doesn’t work for me even though it goes straight from the Firebase documentation. I had to change package’s name from
Firebase
tofirebase-ios-sdk
: