问题
I'm working on a project in Xcode and am attempting to install and use the CryptoSwift package via the Swift Package Manager.
I read the documentation on SPM, but I don't see instructions on how to invoke the SPM through Xcode.
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?
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.
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.
回答1:
Swift Package Manager now support generating Xcode project with
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:
Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.
Note:
- It might not work well if there is a space in your package name, i.e. change "App Store" to "AppStore".
回答2:
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.
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.
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.
回答3:
June 4th, 2019 update. Swift 5 and SPM 5 has added this support and Xcode 11 integrates with SPM.
来源:https://stackoverflow.com/questions/34323239/how-to-install-package-in-xcode-via-swift-package-manager