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
Packagetarget called.binaryTarget, in here we provide the XCFramework module name, an https URL, and a verification checksum:
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.library(name: "MyPackage", targets: ["MyPackage"])
],
dependencies: [
],
targets: [
.binaryTarget(
name: "MyPackage",
url: "https://example.com/MyPackage/MyPackage-1.0.0.xcframework.zip",
checksum: "6d988a1a27418674b4d7c31732f6d60e60734ceb11a0ce9b54d1871918d9c194"
)
]
)We use the usual
productsapi to vend the binary framework.To generate the
checksumwe can use the newswift package compute-checksumcommand:
swift package compute-checksum MyPackage-1.0.0.xcframework.zipFor more information on how to create a binary, refer to the
Binary Frameworks In Swiftsession.
