Swift: Install package so available to any Xcode Project?
This is not something that Swift supports at the current time.
What you could do is clone the Git repo for a project, and then reference it as a local dependency, but I wouldn't recommend this.
How to use Swift Package Manager(SPM) in cli?
I have followed those steps to solve the problem.
- set git HTTP proxy
git config --global http.proxy http://0.0.0.0:1087
git config --global http.proxy socks5://0.0.0.0:1080
- set ssh proxy for host
Append those lines at the end of ~/.ssh/config
to add a socks5 proxy
Host github.com
ProxyCommand nc -X 5 -x 0.0.0.0:1080 %h %p
- use xcodebuild command to resolve package dependencies
Remember you must add the -scmProvider system
option to force xcodebuild to use system git and git configurations, or it will use the xcode built-in git which will never go through the proxy.
xcodebuild -resolvePackageDependencies -scmProvider system
Some references here:
- Building Swift Packages or Apps that Use Them in Continuous Integration Workflows
Add forked Swift Package in Xcode project
I finally worked around this limitation by manually editing both the project.pbxproj and Packages.resolved files, so that they point to the specific commit in the fork of the repository.
To do this, close Xcode and then open the two files with a plain text editor.
In the project.pbxproj file, change the url of the repo and the parameters needed to correctly specify the version rule. In my case, I wrote the hash of the commit I needed:
/* Begin XCRemoteSwiftPackageReference section */
7902F77227C64GF9001583F1 /* XCRemoteSwiftPackageReference "Cuckoo" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ajpallares/Cuckoo";
requirement = {
kind = revision;
revision = a9d239ff1bb93fe0204f8285d513f3139b51fbbb;
};
};
Do the same for the Packages.resolved file:
{
"package": "Cuckoo",
"repositoryURL": "https://github.com/ajpallares/Cuckoo",
"state": {
"branch": null,
"revision": "a9d239ff1bb93fe0204f8285d513f3139b51fbbb",
"version": "null"
}
Obviously, this is not the ideal solution but at least it works ¯\(ツ)/¯
In fact, this seems to be an intended limitation of Swift Package Manager. See:
- https://forums.swift.org/t/dependency-mirroring-and-forking/13902
- https://forums.swift.org/t/replace-dependency-in-graph-with-a-fork/39718
Adding Swift 3 packages to Xcode 8 using the Swift package manager
Xcode and the SPM can work together, but as far as I can tell you do need to take one step on the command line.
Put your package manifest file into the same directory as the Xcode project, and then invoke swift package generate-xcodeproj
The package manager will pull down your dependencies and rewrite the .xcodeproj file to refer to them.
It will preserve any existing source, but the directory structure will be reconfigured to SPM's preferred arrangement:
PROJECT_DIR
├── Sources
│ └── ProjectName
│ ├── YourCode.swift
│ └── YourOtherCode.swift
├── Dependencies
│ └── SomeDependency
│ ├── DependencyCode.swift
│ └── OtherDependencyCode.swift
└── Package.swift
N.B., I haven't tested this extensively on a live project; given the fact that SPM docs still say WIP, please make sure you've made a recent commit.
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
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
Related Topics
Swiftui Views with a Custom Init
Swift - Lazy Var VS. Let When Creating Views Programmatically (Saving Memory)
Swift Draw Shadow to a Uibezier Path
Local Swift Packages Stopped Working in Xcode 13
Difference Between Dispatchqueue Types in Swift
Swiftui - How to Set the Title of a Navigationview to Large Title (Or Small)
Single and Double Taps on Uitableviewcell in Swift 3
Swiftui Navigationview Trying to Pop to Missing Destination (Monoceros)
How to Set an Ordered Relationship with Nspersistentcloudkitcontainer
Enable + Disable Auto-Layout Constraints
What Language Is Swift Written In
How to Highlight a Uitextview's Text Line by Line in Swift
Reading from the Clipboard with Swift 3 on MACos
Uiimage Created from Mtkview Results in Color/Opacity Differences
Using Cocoa Nssavepanel in Sandbox Causes Assertion Failure
How to Handle Touch Gestures in Swiftui in Swift Uikit Map Component
What's the Best Approach to Prefill Core Data Store When Using Nspersistentcloudkitcontainer