如何通过Swift包管理器在Xcode中安装包

时间:2023-01-24 10:09:48

I'm working on a project in Xcode and am attempting to install and use the CryptoSwift package via the Swift Package Manager.

我正在开发一个Xcode中的项目,并试图通过Swift包管理器来安装和使用这个密码Swift包。

I read the documentation on SPM, but I don't see instructions on how to invoke the SPM through Xcode.

我阅读了关于SPM的文档,但是没有看到如何通过Xcode调用SPM的说明。

The examples often refer to calling $ swift build. Does this mean that the SPM is only accessible from the command line? And if so, where exactly am I supposed to create the Package.swift file?

这些例子通常指的是调用$ swift构建。这是否意味着SPM只能从命令行访问?如果是的话,我应该在哪里创建这个包。快速文件?

I'm reasonably familiar with Xcode, but I don't really understand the meaning of the build settings part of a project, or how Swift modules are used.

我对Xcode相当熟悉,但我并不真正理解项目的构建设置部分的含义,也不理解如何使用Swift模块。

If more context is needed, this is the project I'm working on in Xcode.

如果需要更多的上下文,这就是我在Xcode中进行的项目。

EDIT: This question was originally asked for Xcode 7.2, which shipped with Swift 2.1.1. Will gladly accept answers that explain how to do this with current/future versions of Xcode.

编辑:这个问题最初是问Xcode 7.2,它随Swift 2.1.1一起发送。将欣然接受解释如何使用当前/未来版本的Xcode实现这一点的答案。

2 个解决方案

#1


17  

Swift Package Manager now support generating Xcode project with

Swift包管理器现在支持使用Xcode项目生成

swift package generate-xcodeproj

as mentioned in this answer, but this only works when developing a library, or a command line tool. Not (yet) for (iOS/OS X) graphical application developer:

正如在这个答案中提到的,但是这只适用于开发库或命令行工具。(iOS/OS X)图形应用程序开发人员(尚未):

Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

请注意,此时包管理器不支持iOS、watchOS或tvOS平台。

Note:

注意:

  • It might not work well if there is a space in your package name, i.e. change "App Store" to "AppStore".
  • 如果包名中有空格,比如将“应用程序商店”改为“应用程序商店”,那么它可能无法正常工作。

#2


13  

At present, to use the Swift Package Manager aka SPM, you need to install the development version of Swift 2.2 provided by Apple here. Xcode 7.2 shipped with Swift 2.1.1 and does not work with the SPM unless Swift 2.2-dev is installed.

目前,要使用Swift包管理器即SPM,需要在这里安装Apple提供的Swift 2.2的开发版本。Xcode 7.2与Swift 2.1.1一起发货,除非安装Swift 2.2-dev,否则不会使用SPM。

You can compile with Swift 2.2-dev but you will need to do the build of CryptoSwift on the command line using swift build. When the library and modulemaps are built, you can drag and drop them into Xcode 7.2 using the Finder. SPM puts the required files into a .build directory. But Xcode 7.2 needs to be started with the alternate toolchain. This can be done from the command-line using xcrun launch-with-toolchain /Library/Developer/Toolchains/swift-latest.xctoolchain You should be able to import from the modules/libraries built with the SPM.

可以使用Swift 2.2-dev编译,但是需要使用Swift构建在命令行上构建Swift。构建库和模块时,可以使用查找器将它们拖放到Xcode 7.2中。SPM将所需的文件放入.build目录中。但是Xcode 7.2需要从备用工具链开始。这可以通过使用xcrun的命令行完成——带有工具链/库/开发人员/工具链/swift-latest。您应该能够从使用SPM构建的模块/库中导入xctoolchain。

Note though, that you cannot submit iOS apps to the Store at the moment that have been built with the 2.2 development version. You can build/run/test things generally without problem, although Playgrounds are not functional and there can be Xcode issues with the debugger.

不过请注意,目前还不能向商店提交使用2.2开发版本构建的iOS应用程序。您可以毫无问题地构建/运行/测试东西,尽管游乐场没有功能,调试器可能存在Xcode问题。

#1


17  

Swift Package Manager now support generating Xcode project with

Swift包管理器现在支持使用Xcode项目生成

swift package generate-xcodeproj

as mentioned in this answer, but this only works when developing a library, or a command line tool. Not (yet) for (iOS/OS X) graphical application developer:

正如在这个答案中提到的,但是这只适用于开发库或命令行工具。(iOS/OS X)图形应用程序开发人员(尚未):

Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

请注意,此时包管理器不支持iOS、watchOS或tvOS平台。

Note:

注意:

  • It might not work well if there is a space in your package name, i.e. change "App Store" to "AppStore".
  • 如果包名中有空格,比如将“应用程序商店”改为“应用程序商店”,那么它可能无法正常工作。

#2


13  

At present, to use the Swift Package Manager aka SPM, you need to install the development version of Swift 2.2 provided by Apple here. Xcode 7.2 shipped with Swift 2.1.1 and does not work with the SPM unless Swift 2.2-dev is installed.

目前,要使用Swift包管理器即SPM,需要在这里安装Apple提供的Swift 2.2的开发版本。Xcode 7.2与Swift 2.1.1一起发货,除非安装Swift 2.2-dev,否则不会使用SPM。

You can compile with Swift 2.2-dev but you will need to do the build of CryptoSwift on the command line using swift build. When the library and modulemaps are built, you can drag and drop them into Xcode 7.2 using the Finder. SPM puts the required files into a .build directory. But Xcode 7.2 needs to be started with the alternate toolchain. This can be done from the command-line using xcrun launch-with-toolchain /Library/Developer/Toolchains/swift-latest.xctoolchain You should be able to import from the modules/libraries built with the SPM.

可以使用Swift 2.2-dev编译,但是需要使用Swift构建在命令行上构建Swift。构建库和模块时,可以使用查找器将它们拖放到Xcode 7.2中。SPM将所需的文件放入.build目录中。但是Xcode 7.2需要从备用工具链开始。这可以通过使用xcrun的命令行完成——带有工具链/库/开发人员/工具链/swift-latest。您应该能够从使用SPM构建的模块/库中导入xctoolchain。

Note though, that you cannot submit iOS apps to the Store at the moment that have been built with the 2.2 development version. You can build/run/test things generally without problem, although Playgrounds are not functional and there can be Xcode issues with the debugger.

不过请注意,目前还不能向商店提交使用2.2开发版本构建的iOS应用程序。您可以毫无问题地构建/运行/测试东西,尽管游乐场没有功能,调试器可能存在Xcode问题。