使用 Swift Package Manager 时如何生成用于开发的 Xcode 项目文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34116041/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:17:30  来源:igfitidea点击:

When using Swift Package Manager how can I generate an Xcode project file for development

xcodeswiftpackage-managersswift-package-manager

提问by Avner Barr

I am using the new open source Swift Package Manager and am able to download the files. I want the manager to create a "development environment" (Through Xcode) based on the packages it retrieved.

我正在使用新的开源 Swift 包管理器并且能够下载文件。我希望经理根据它检索到的包创建一个“开发环境”(通过 Xcode)。

Has anybody dealt with this?

有没有人处理过这个?

回答by Regexident

As of PR #174on the swift-package-managerproject, there exists an option for generating an Xcode project file in root directory of the package:

swift-package-manager项目的PR #174开始,有一个选项可以在包的根目录中生成一个 Xcode 项目文件:

$ swift package generate-xcodeproj

Note: Earlier builds used:

注意:早期版本使用:

$ swift build --generate-xcodeproj

It will officially be part of Swift's 3.0 release.
But it is already available with Xcode Swift DEVELOPMENT Snapshot 2016-03-24or later!

它将正式成为 Swift 3.0 版本的一部分。
但它已经可用Xcode Swift DEVELOPMENT Snapshot 2016-03-24或以后!

回答by Kostiantyn Koval

Update: as mentioned in other answers, you can now generate Xcode project files with this command:

更新:如其他答案中所述,您现在可以使用以下命令生成 Xcode 项目文件:

swift package generate-xcodeproj


Original answer:

原答案:

The Swift Package Manger (SPM) is cross platform, It works on Mac and Linux. The Xcode is Mac OS only, so I don't think SPM will be hard integrate to work with Xcode.

Swift Package Manger (SPM) 是跨平台的,适用于 Mac 和 Linux。Xcode 仅适用于 Mac OS,因此我认为 SPM 不会很难与 Xcode 集成。

SPM can do 2 things:

SPM 可以做两件事:

  • Build swift source code into modules (Executable and Library)
  • Fetch dependencies (from git or local path)
  • 将 swift 源代码构建到模块中(可执行文件和库)
  • 获取依赖项(从 gi​​t 或本地路径)

The SPM work only with Source code, folders and files. It doesn't know anything about Xcode.
Also it is mentioned that in the future Apple plans to add support for other languages not only Swift and Objc.

SPM 仅适用于源代码、文件夹和文件。它对 Xcode 一无所知。
还提到,未来苹果计划增加对其他语言的支持,不仅仅是 Swift 和 Objc。

My answer: SPM will not ingrate with Xcode. But because it's open-source anyone can just make its own fork and add custom feature that would generate Xcode specific files.

我的回答是:SPM 不会忘记 Xcode。但是因为它是开源的,所以任何人都可以制作自己的 fork 并添加自定义功能来生成 Xcode 特定文件。

回答by Vinh Nguyen

I wrote a small command line tool for that

我为此写了一个小的命令行工具

it's called spawn: https://github.com/vinhnx/spawn

它叫做spawnhttps: //github.com/vinhnx/spawn

Basically, it's just a small combination of repetitive commands when you want to try out a SPM package:

基本上,当您想试用 SPM 包时,它只是重复命令的一小部分组合:

$ swift package update # update or resolve package dependencies
$ swift package generate-xcodeproj # generate a .xcodeproj to edit on Xcode
$ xed . # open generated .xcodeproj automatically