Publishing a Swift package: SwiftPM, Git tags and the Swift Package Index

A Swift package is a directory with a Package.swift manifest and source files. There is no central upload step like npm or PyPI: a “published” package is just a Git repository that other people can reach, plus semantic-version tags. The Swift Package Manager (SwiftPM) clones the repo and checks out the tag that matches the version requirement.
Prerequisites
Section titled “Prerequisites”- A Swift toolchain from swift.org, or Xcode on macOS (it includes Swift and SwiftPM).
- Git, and an account on a Git host such as GitHub, GitLab or Bitbucket.
Step 1: create the package
Section titled “Step 1: create the package”swift package init names the package after the current directory, so create that first:
mkdir MyPackagecd MyPackageswift package init --type libraryUse --type executable for a command-line tool. Recent toolchains generate:
MyPackage├── .gitignore├── Package.swift├── Sources│ └── MyPackage│ └── MyPackage.swift└── Tests └── MyPackageTests └── MyPackageTests.swiftDepending on your toolchain, the generated test uses Swift Testing (import Testing, @Test) or XCTest. Pass --enable-swift-testing or --enable-xctest to choose explicitly.
Step 2: edit the manifest
Section titled “Step 2: edit the manifest”Package.swift declares the package’s name, supported platforms, the products other packages can use, its dependencies and its targets:
import PackageDescription
let package = Package( name: "MyPackage", platforms: [ .macOS(.v10_15), .iOS(.v13), ], products: [ .library(name: "MyPackage", targets: ["MyPackage"]), ], dependencies: [ // .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"), ], targets: [ .target(name: "MyPackage"), .testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]), ])The first-line comment is required. It sets the minimum Swift toolchain that can build the package, and which manifest APIs you may use. swift package init writes your toolchain’s version there. Lower it only if you need to support older compilers. Only list platforms if you actually need a newer minimum OS than SwiftPM’s default.
The products entry is what consumers depend on. A target that isn’t exposed through a product can’t be imported by other packages.
Step 3: implement and test
Section titled “Step 3: implement and test”Put your code in Sources/MyPackage and your tests in Tests/MyPackageTests. Anything other packages should use must be marked public, because the default internal access level isn’t visible outside the module. Then build and test:
swift buildswift testStep 4: commit and tag a version
Section titled “Step 4: commit and tag a version”SwiftPM resolves versions from Git tags, and the tags must be semantic versions:
git init -b maingit add .git commit -m "Initial commit"git tag 0.1.0A tag points at one commit. To release changes later, commit them and create a new tag such as 0.1.1 or 0.2.0. Don’t move an existing tag: anyone who already resolved it has that commit pinned in their Package.resolved.
Step 5: push to a public repository
Section titled “Step 5: push to a public repository”Create an empty repository on your Git host, then push the branch and the tag:
git remote add origin https://github.com/YourUsername/MyPackage.gitgit push -u origin maingit push origin 0.1.0That’s the publish step. Anyone with access to the repository can now depend on it.
Step 6: use it from another package
Section titled “Step 6: use it from another package”In the consuming package’s Package.swift:
dependencies: [ .package(url: "https://github.com/YourUsername/MyPackage.git", from: "0.1.0"),],targets: [ .target( name: "App", dependencies: [ .product(name: "MyPackage", package: "MyPackage"), ] ),]from: accepts any version up to the next major, so 0.1.0 here matches 0.1.0 ..< 1.0.0. In Xcode, use File → Add Package Dependencies… and paste the repository URL.
Step 7: list it on the Swift Package Index
Section titled “Step 7: list it on the Swift Package Index”The Swift Package Index is the main place people search for Swift packages. It builds your package against several Swift versions and platforms to show compatibility, and can host your DocC documentation. To be listed, the repository must be public, have Package.swift at the root, have at least one semantic-version tag, and build without errors. Submit the URL (including https:// and .git) through the Add a Package page, which opens an issue on the index’s PackageList repository.
Gotchas
Section titled “Gotchas”- Package and product names are part of your public API. Renaming either breaks every consumer’s manifest.
- Packages depending on yours must use a tagged version (or an explicit branch/revision). Untagged commits on
mainaren’t picked up byfrom:requirements. - Breaking changes need a new major version. After 1.0.0, consumers using
from:won’t pick up 2.0.0 until they change their manifest.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)