使用 Swift 包管理器将 Swift 3 包添加到 Xcode 8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39708845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding Swift 3 packages to Xcode 8 using the Swift package manager
提问by Garry Pettet
I am new to Swift and Xcode. I am running macOS Sierra and Swift 3.
我是 Swift 和 Xcode 的新手。我正在运行 macOS Sierra 和 Swift 3。
For my first forays in Swift, I am developing a simple command line tool. There are a couple of Swift packages that I want to use and the installation instructions for both packages on GitHub says to use the Swift package manager by simply adding them as dependencies in the package manifest file.
在我第一次尝试 Swift 时,我正在开发一个简单的命令行工具。我想使用几个 Swift 包,GitHub 上这两个包的安装说明说,只需将它们作为依赖项添加到包清单文件中即可使用 Swift 包管理器。
What I can't figure out is how to do this in Xcode. Do I just create a 'package.swift' file in the root of my project? Doing this and then running the project doesn't seem to work as the required packages don't seem to be added to my project.
我不知道如何在 Xcode 中做到这一点。我只是在我的项目的根目录中创建一个“package.swift”文件吗?这样做然后运行项目似乎不起作用,因为所需的包似乎没有添加到我的项目中。
Am I doing something wrong?
难道我做错了什么?
回答by jscs
Xcode and the SPM can work together, but as far as I can tell you do need to take one step on the command line.
Xcode 和 SPM 可以一起工作,但据我所知,您确实需要在命令行上迈出一步。
Put your package manifest file into the same directory as the Xcode project, and then invoke swift package generate-xcodeproj
将你的包清单文件放到与Xcode项目相同的目录中,然后调用 swift package generate-xcodeproj
The package manager will pull down your dependencies and rewrite the .xcodeproj file to refer to them.
包管理器将拉下您的依赖项并重写 .xcodeproj 文件以引用它们。
It willpreserve any existing source, but the directory structure will be reconfigured to SPM's preferred arrangement:
它会保留所有现有的来源,但该目录结构将被重新配置,以SPM偏好配置:
PROJECT_DIR
├── Sources
│ └── ProjectName
│ ├── YourCode.swift
│ └── YourOtherCode.swift
├── Dependencies
│ └── SomeDependency
│ ├── DependencyCode.swift
│ └── OtherDependencyCode.swift
└── Package.swift
N.B., I haven't tested this extensively on a live project; given the fact that SPM docs still say WIP, please make sure you've made a recent commit.
注意,我还没有在实际项目中对此进行过广泛的测试;鉴于 SPM 文档仍然说 WIP,请确保您最近进行了提交。
回答by thSoft
In addition to running swift package generate-xcodeproj
, I had to build my project in Xcode before I could use the installed packages.
除了运行之外swift package generate-xcodeproj
,我还必须在 Xcode 中构建我的项目,然后才能使用已安装的包。