Reputation: 20496
I have a project in Xcode 11 that I added Swift Package Manager dependencies to. I now realized that I no longer need one of the package dependencies I previously added to my project.
As you can see below, there are no options under File > Swift Packages
for deleting a packager from Swift Package Manager for this project.
I have tried removing the package from the array in the project.xcworkspace/xcshareddata/swiftpm/Package.resolved
file. But it still doesn't remove it from Xcode, and the next time I Update to Latest Package Versions
it readds the entry to the Package.resolved
file.
How can I delete a Swift Package Manager dependency in my project?
Upvotes: 360
Views: 187892
Reputation: 3
I'm using Xcode 16.1 and the steps were different for me. Here's how I did it:
In the Project Navigator on the left, select your project.
Ensure you're on the General tab.
Scroll down to Frameworks, Libraries, and Embedded Content section.
Click to select the dependency you wish to remove, click the minus symbol (-
), and confirm via the popup that appears.
I hope this helps, let me know if you have any questions or trouble with the steps.
Upvotes: 0
Reputation: 1
try deleting the package dependencies and reinstalling using the latest major version (i.e. 10.0.0). i downloaded realm using swift package manager with the latest version 10.48.1 and couldnt import swiftRealm. make sure to add to target. after adding the dependencies it automatically updated to latest version since i used dependency rule "up to next major version"
Upvotes: -2
Reputation: 4239
select your project and move to the package dependencies tab then select and remove
Please follow the image
Upvotes: 61
Reputation: 2177
Please follow the steps below to remove a particular package from the Xcode project smoothly.
Upvotes: 15
Reputation: 1808
Dependencies keep poping up even after remove pod and reinstall pod.
Upvotes: 17
Reputation: 49
There's no answer to what I've found. If the git link has been broken, *.xcodeproj/project.pbxproj must be changed to the proper link. Xcode will catch the modification and update automatically.
Upvotes: 0
Reputation: 9915
As other answers have mentioned, we can import Swift Packages into a project very easy through the File -> Swift Packages -> Add Package Dependency workflow, and that works for the majority of applications. I have added this answer as a further optimisation for packages with nested dependencies.
Swift Packages are imported not just with the Git source code checkout, but also with one, or several Package Products. In my case, I wanted to keep the Package because I used it in one target but not in another target. Sometimes a Package contains multiple dependencies which we don't need, and this is a great opportunity to prune unused dependencies.
I recently made a mistake where I automatically imported all the modules referenced by a Swift Package dependency, even those I don't need. This is common because Packages can have multiple Products which each expose different APIs for different applications.
If you aren't sure if you need an import, check it and delete it. For example, a Package could include an Objective-C Module that adds an additional unnecessary import.
In my case, I imported a Swift Package that was exported via multiple nested libraries: OHHTTPStubs
and OHHTTPStubsSwift
in the above example.
We can delete nested Swift Package dependencies via Build Phases or the Target General settings tab without deleting the Package itself. Deleting unnecessary dependencies is a good practice to save your app's memory footprint and also streamlines build times.
Each target should only import the libraries it uses.
Rules:
OHHTTPStubsSwift
is the equivalent Swift CocoaPods subspec that adds a nicer API wrapper over the ObjC API but already imports the ObjC API (OHHTTPStubs
).
I deleted the Package Products from the Host Target because I was only using it in UI Tests. I then only imported the OHHTTPStubsSwift
via Build Phases.
Upvotes: 1
Reputation: 10
Step 1. Navigate to your project directory. Step 2. Find 'your-project.xcodeproj' Step 3. Open it in text editor, not Xcode (you have to use finder and use any text editor by opening with-all applications -> text editor Step 4. Search for all instances of the package in question, for instance...I had a package 'UIKit' that was causing issues, and I just removed any instances of it and made sure not to disturb the rest of the file. Step 4. Open/Re-open xcode project with xcode and enjoy.
Upvotes: -1
Reputation: 34175
Swift Package Manager(SPM) Dependency
Add dependency
1. Project Settings contains information about dependencies.
2. File -> Swift Packages -> Add Package Dependency...
3. Target -> General -> Frameworks, Libraries, and Embedded Content -> Add Items -> Add Other... -> Add Package Dependency...
Target Settings includes product from dependency
Edit dependency
To edit URL you can edit .pbxproj
with repositoryURL
Delete dependency
Project -> Packages -> <Select dependency> -> -
[Local Swift Package Manager(SPM)]
[iOS Dependency manager]
Upvotes: 35
Reputation: 8671
I removed the swift package, but its dependancies were still showing in the project. I saw the swift package was still in the Frameworks folder at the bottom of left pane,
I removed it from there and the dependencies are gone.
Upvotes: 3
Reputation: 636
Firstly I removed it from dependencies and targets in Package.swift, then i regenerated my project file with swift package generate-xcodeproj
Upvotes: 1
Reputation: 9266
In addition to Pierre's answer, this was driving me crazy, I had a sub project that I was editing, I forgot about that (it was in a subfolder). Even though I removed it in the "Swift Packages" pane it kept coming back. Removing that sub folder reference made sure the PM dependencies went away.
Upvotes: 3
Reputation: 11633
You'll be able to manage your packages (add / remove)
Upvotes: 822