请教一下,swift包管理怎么用?我创建了一个swift项目,然后在根目录创建了一个Package.swift文件,
代码如下:
import PackageDescription
let package = Package(
name: "Format",
dependencies: [
.Package(url: "https://github.com/marmelroy/Format.git", majorVersion: 1),
]
)
但是这里“ PackageDescription”报错,系统提示没有这个库,使用swift build也无效。
这个是什么问题,请大神解答一下。
PHP中文网2017-04-17 17:53:46
First of all, my understanding is that SwiftPM (Swift Package Manager) is not used like this in Xcode. Instead, it is done directly from the command line.
Official introduction:
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Probably means, you can directly use SwiftPM to download, compile, and link your Swift code and dependencies
Currently (Xcode 7.3) installed on OS
$ swift build
error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build (No such file or directory)
swift build
时会报错,如下:
$ export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"
所以,你需要去下载开发版本的 swift。以下为解决方案:
去官方下载 Swift Trunk Development (master) 版本(即 dev 版本, 与 Xcode 使用版本不冲突)。传送门
下载下来应该是 swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-osx.pkg
So, you need to download the development version of swift. The following is the solution:
swift-DEVELOPMENT-SNAPSHOT-2016-03-24-a-osx.pkg
, which is about 200MBConfigure the latest Swift version into environment variables. Open the command line and execute
$ swift build --version
Apple Swift Package Manager 0.1
Then check if the installation is successful
$ cd ~/Desktop
$ mkdir helloSwiftPM
$ cd helloSwiftPM
Use
First, create an empty directory🎜
$ swift build --init
🎜Then, initialize this directory. 🎜
$ swift build
🎜Compile🎜
$ .build/debug/helloSwiftPM
Hello, world!
🎜Run🎜
rrreee
🎜This is OKPHPz2017-04-17 17:53:46
swift package generate-xcodeproj first generates the xcode project file. Then just open it.