Xcode 13.3 shows warnings for deprecation on the dependencies for external packages.
// swift-tools-version:5.6
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [
.iOS(.v15)
],
products: [
.library(
name: "MyPackage",
targets: ["MyTarget"]),
],
dependencies: [
.package(
name: "MyDependency",
url: "https://github.com/someorg/somepackage.git",
.branch("main"))
],
targets: [
.target(
name: "MyTarget",
dependencies: ["MyDependency"])
]
)
This shows the warning:
'package(name:url:_:)' is deprecated: use specific requirement APIs instead (e.g. use 'branch:' instead of '.branch')
However applying the recommended update makes the dependency not reachable anymore from MyPackage
.
It is necessary to set the dependency as a product.
Specifically with .product(name: [PackageName], package: [Name of repository])
, example:
// swift-tools-version:5.6
import PackageDescription
let package = Package(
name: "MyPackage",
platforms: [
.iOS(.v15)
],
products: [
.library(
name: "MyPackage",
targets: ["MyTarget"]),
],
dependencies: [
.package(
url: "https://github.com/someorg/somepackage.git",
branch: "main")
],
targets: [
.target(
name: "MyTarget",
dependencies: [
.product(
name: "MyDependency",
package: "somepackage")])
]
)
This is still relevant in Xcode 14.3.1
if you have a package with multiple products/libraries.