xcode 没有这样的模块“PackageDescription”

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

No such module "PackageDescription"

iosswiftxcodeswift3

提问by Ahsan Attari

I just started with swift 3 and made a simple app in xcode using Swift 3.0 . Now i want to add a third party libraryusing Swift Package Manager . I am following installation method given in this link . I created Package.swiftfile which looks like this

我刚开始使用 swift 3 并使用 Swift 3.0 在 xcode 中制作了一个简单的应用程序。现在我想使用 Swift Package Manager添加第三方。我正在遵循此链接中给出的安装方法。我创建了Package.swift看起来像这样的文件

import PackageDescription

let package = Package (
name : "SwiftPM",
dependencies : [
.Package(url: "https://github.com/ArtSabintsev/Siren.git", majorVersion: 1)
])

but i get error No such module "PackageDescription"

但我得到错误 No such module "PackageDescription"

回答by GoZoner

The Swift Package Manager and Xcode are orthogonal. That is, you can't expect to compile Package.swift in Xcode; it simply won't work. Instead, until Xcode supports the package manager, you need to have two distinct builds - one with the package manager and one with Xcode.

Swift Package Manager 和 Xcode 是正交的。也就是说,你不能指望在 Xcode 中编译 Package.swift;它根本行不通。相反,在 Xcode 支持包管理器之前,您需要有两种不同的构建——一种带有包管理器,一种带有 Xcode。

So, using the Swift Package Manager, once you've defined Package.swift and formulated your directory structure as expected by the package manger, you perform simply:

因此,使用 Swift 包管理器,一旦您定义了 Package.swift 并按照包管理器的预期制定了目录结构,您只需执行以下操作:

swift build

Then for Xcode, you create an Xcode project that uses your source code, but not Package.swift. You'll need to clone the Siren.git project, explicitly - into your Xcode build's source files.

然后对于 Xcode,您创建一个使用源代码的 Xcode 项目,但不使用 Package.swift。您需要将 Siren.git 项目明确地克隆到您的 Xcode 构建的源文件中。

回答by Pratik

Swift 3/4

斯威夫特 3/4

Navigate to your project folder through a terminal and run these commands swift package init --type libraryfirst and then swift package generate-xcodeproj

通过终端导航到您的项目文件夹swift package init --type library,然后先运行这些命令swift package generate-xcodeproj

Reference

参考