Publish your Swift package privately, or share it globally with other developers.
- Swift Package Manager
Making your Swift packages available online enables you to use the support for Swift package dependencies in Xcode. By publishing your Swift packages to private Git repositories, you can manage and integrate internal dependencies across your projects, allowing you to reduce duplicate code and promote maintainability. Publish your packages publicly, and share your code with developers around the world. To get started, you just need a Swift package and an account with a provider of hosted Git repositories.
Provide Information on Your Swift Package
Every newly created Swift package comes with a blank
Readme file for you to modify. Consider adding enough information in the README file so other developers know how to use your Swift package, such as:
A description of the functionality of your Swift package
Supported platforms and versions of Swift
Some developers even choose to include tutorials or usage documentation as part of their
Put Your Local Swift Package Under Version Control
When you create a new Swift package with Xcode, check “Create Git repository on my Mac” in the sheet for creating a new package. In case you want to put your local package under version control at a later time, you can do so using Xcode. Open your Swift package, select the Source Control menu, choose Create Git Repositories, check the checkbox next to your package, and click Create.
This process initializes a Git repository, adds your package to the staging area, and commits your files.
Tag Your Latest Commit
It’s a best practice to create a version tag for a Swift package; however, there are other ways to add a package to a project, as described in Adding Package Dependencies to Your App. To create a version tag, tag the last commit with the package version. A package version is a three period-separated integer. An example is
1 The package version must conform to semantic versioning in order to ensure that your package behaves in a predictable manner once developers update their package dependency to a newer version.
To learn more about the semantic versioning standard, visit semver.org.
In the Source Code Navigator, click the disclosure triangle next to Branches to disclose the list of your branches, then select a branch. In the history editor, Control-click a commit, then choose Tag “Your Identifier” from the pop-up menu. In the sheet that appears, enter a tag name that follows the semantic versioning standard, such as
1. You can add an optional message, then click Create.
Make Your Swift Package Publicly Available
Make sure that the Source Control Navigator is visible and that you select your local repository. Right-click it, and choose Create [packageName] Remote. In case you’ve already created an empty remote repository for your Swift package, you can choose Add Existing Remote.
Next, push your local changes and the version tag to your Git remote. Click the Source Control menu, select Push, choose the branch from the dropdown menu, check the checkbox next to Include Tags, and click Push.
Ensure your Git repository is public, and let people know that the package exists. Other developers only need the package’s Git URL to get started.
Learn more about adopting package dependencies in Adding Package Dependencies to Your App.