如何将包集合添加到我的 Xcode 项目中?

How can I add a package collection to my Xcode project?

在 Xcode 12.5 和 iOS 部署目标 14.5 我想导入 swift-collections 库以使用模块 OrderedDictionary.

当我添加以下 URL https://developer.apple.com/swift/packages/collections/apple.json 作为包存储库时,出现以下错误:

我认为这是授权问题。我应该在哪里输入我的凭据?

Swift 5.5 和 Xcode 13+

包 Collections 在 Swift 5.5 和 Xcode 13.

中引入

来自Swift.org

You can add it using the new package-collection add option from the SwiftPM command line

$ swift package-collection add https://developer.apple.com/swift/packages/collections/apple.json

执行上述命令后,select 您的项目在 Xcode 项目导航器中,select 它再次出现在项目和目标列表中,并切换到 Swift Packages 选项卡并单击 Packages 列表下方的 + 按钮,您将看到一个 collections 列表。并从列表中添加 swift-collections 包。

注意:确保您至少安装了 Swift 5.5。您可以查看您 运行 swift --version.

的 Swift 版本

低于Xcode13

有效的URL是:https://github.com/apple/swift-collections

您必须添加 swift collections 包而不是 json。

检查 here

中的 Using Swift Collections in your project 部分

安装后,您将获得 select离子靶的以下选项卡。并且 select 已订购 Collections 目标。

文档: https://github.com/apple/swift-collections/blob/main/Documentation/OrderedDictionary.md