Combined Swift packages
If we want to distribute a Swift package as both a library that other tools can import, and as a command line tool, all we have to do is to define two separate targets and products.
Here’s an example
Package.swift file in which we’re doing exactly that:
// swift-tools-version:5.0 import PackageDescription let package = Package( name: "Plot", products: [ // If we want to distribute a Swift package as both a // library and a command line tool, one way to do that // is to simply use lower case characters for the CLI. .library(name: "Plot", targets: ["Plot"]), .executable(name: "plot", targets: ["PlotCLI"]) ], dependencies: [ .package(url: "https://github.com/johnsundell/files.git", from: "3.1.0"), .package(url: "https://github.com/johnsundell/sweep.git", from: "0.2.1"), .package(url: "https://github.com/johnsundell/codextended.git", from: "0.2.0") ], targets: [ .target( name: "Plot", dependencies: ["Files", "Sweep", "Codextended"] ), .target( // We can still name our target "CLI", to make it // easier to see the difference between our CLI // and our library in Xcode. name: "PlotCLI", dependencies: ["Plot"] ), .testTarget( name: "PlotTests", dependencies: ["Plot", "Codextended"] ) ] )
For two weeks, many websites around the Swift community are featuring indie developers who have been financially impacted by the current pandemic. If you can, please help support these indies by downloading their apps. Today’s app is...
Working Copy: My favorite Git client for iOS. Working Copy lets me access all of my Git repositories while on the go, which lets me update my projects, check out files, and much more. Made by Anders Borum from Copenhagen.