使用 Swift 包管理器将 Swift 3 包添加到 Xcode 8 [英] Adding Swift 3 packages to Xcode 8 using the Swift package manager

查看:25
本文介绍了使用 Swift 包管理器将 Swift 3 包添加到 Xcode 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Swift 和 Xcode 的新手.我正在运行 macOS Sierra 和 Swift 3.

I am new to Swift and Xcode. I am running macOS Sierra and Swift 3.

在我第一次尝试 Swift 时,我正在开发一个简单的命令行工具.我想使用几个 Swift 包,GitHub 上这两个包的安装说明说,只需将它们作为依赖项添加到包清单文件中即可使用 Swift 包管理器.

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.

我不知道如何在 Xcode 中执行此操作.我只是在我的项目的根目录中创建一个package.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 和 SPM 可以协同工作,但据我所知,您确实需要在命令行上迈出一步.

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项目所在的目录下,然后调用swift package generate-xcodeproj

Put your package manifest file into the same directory as the Xcode project, and then invoke swift package generate-xcodeproj

包管理器将拉下您的依赖项并重写 .xcodeproj 文件以引用它们.

The package manager will pull down your dependencies and rewrite the .xcodeproj file to refer to them.

保留任何现有源,但目录结构将重新配置为 SPM 的首选排列:

It will preserve any existing source, but the directory structure will be reconfigured to SPM's preferred arrangement:

PROJECT_DIR
├── Sources
│   └── ProjectName
│       ├── YourCode.swift
│       └── YourOtherCode.swift
├── Dependencies
│   └── SomeDependency
│       ├── DependencyCode.swift
│       └── OtherDependencyCode.swift
└── Package.swift

注意,我还没有在实际项目中对此进行过广泛的测试;鉴于 SPM 文档仍然说 WIP,请确保您最近进行了提交.

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.

这篇关于使用 Swift 包管理器将 Swift 3 包添加到 Xcode 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆