使用Swift包管理器在Xcode 8中添加Swift 3包。

时间:2023-01-23 23:53:03

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中这么做。我只是创建一个“包”吗?swift文件在我项目的根目录?这样做然后运行项目似乎并不奏效,因为所需的包似乎没有添加到我的项目中。

Am I doing something wrong?

我做错什么了吗?

2 个解决方案

#1


41  

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 will preserve 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,请确保您已经做了最近的提交。

#2


0  

In addition to running swift package generate-xcodeproj, I had to build my project in Xcode before I could use the installed packages.

除了运行swift包generate-xcodeproj之外,在使用已安装的包之前,我还必须使用Xcode构建我的项目。

#1


41  

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 will preserve 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,请确保您已经做了最近的提交。

#2


0  

In addition to running swift package generate-xcodeproj, I had to build my project in Xcode before I could use the installed packages.

除了运行swift包generate-xcodeproj之外,在使用已安装的包之前,我还必须使用Xcode构建我的项目。