How to Update Swift Dependencies in Xcode

How to update swift package imported to Xcode Project via Swift Package Manager?

Option 1: (Xcode 13 and above)

Right-click on the package from the left navigation pan and select Update Package

Xcode 13

Option 2:

Double click on the package in the tab you mentioned and change the version to anything else. It will then recheck the remote repo. The benefit of doing this is to only update the selected package. (Also, it's better to have the current using version be set in the package.)

Option 3:

From File -> Swift Packages -> Update to Latest Package Versions

SS

How to use dependencies in a Swift Package

Found my answer.

In the target dependencies, need to include the package name as a string:

        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.

        .target(
            name: "DBCore",
            dependencies: [
"AgileDB"
]),

        .testTarget(
            name: "DBCoreTests",
            dependencies: ["DBCore"]),
    ]

Add dependencies to binary targets in Swift Package Manager

I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import for the dependencies in your code to @_implementationOnly import

E.g.

@_implementationOnly import CocoaLumberjack

You can read more about @_implementationOnly here

Xcode: Using packages in Xcode 14

There is a change in the syntax for local packages, the .package(url: … syntax that used to work for packages within the project does not work anymore.

With Xcode 14 local packages that do no have their own repo MUST be referred as:

dependencies: [
.package(path: "../MyLibrary"),
]

Now this works just fine in Xcode 14 beta, but if you're going back to the Xcode release version, you'll get numerous errors. To fix those, reset the package caches by calling

File > Packages > Reset Package Caches

I had the same issue in a project with 14 internal packages, some of them dependent on each other, and it runs fine now in both Xcode 13.4 and Xcode 14 beta.

Hope it helps

SPM dependencies branch is deprecated on Xcode 13.3 and Swift 5.6

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")])
]
)


Related Topics



Leave a reply



Submit