Distribute binary frameworks as Swift packages
Show Apple's description.
Discover how you can add third-party frameworks to your app and keep them up to date using Swift packages in Xcode. We’ll show you how to author packages that reference frameworks, explain binary targets and how to specify them in your package manifest file, and demonstrate how to compute checksums so that your clients always get the exact binary you expect.
Frameworks are distributed in the XCFramework format. For further details on creating and versioning an XCFramework, be sure to watch "Binary Frameworks in Swift" from WWDC19.
- Xcode 12/Swift 5.3 adds SPM support for:
- distribution to closed-source libraries
- binary dependencies
How To Use a Binary Dependency in an App
- Supported only on Apple platforms
- Uses XCFrameworks
- It works exactly as a open source library, you add them in an app in the same way, you add them as a package dependency in the same way.
- The difference is that, instead, of having the source code in the project navigator, we have an XCFramework (with, headers are still visible.
How to Crete/Distribute a Binary Framework as a Swift Package
- With Swift 5.3 we have a new
Package target called
.binaryTarget, in here we provide the XCFramework module name, an https URL, and a verification checksum:
let package = Package(
.library(name: "MyPackage", targets: ["MyPackage"])
- We use the usual
products api to vend the binary framework.
- To generate the
checksum we can use the new
swift package compute-checksum command:
swift package compute-checksum MyPackage-1.0.0.xcframework.zip