35

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.

m81
  • 2,217
  • 5
  • 31
  • 47
  • Any update on this now that 7.3 is out? – John D Feb 19 '16 at 14:54
  • 1
    @JohnD, Swift Package Manager was not released with Xcode 7.3 and Swift 2.2.1. It is expected to be released with Swift 3. – Franklin Yu Jun 09 '16 at 08:35
  • As of today (12/2020), you don't need an xcodeproj (neither to generate-xcodeproj) to build an iOS package. I describe more about that in this answer: https://stackoverflow.com/questions/64758546/can-i-specify-a-platform-target-when-running-swift-test-from-the-cli/65256621#65256621 – itMaxence Dec 11 '20 at 18:55

3 Answers3

17

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".
Franklin Yu
  • 8,920
  • 6
  • 43
  • 57
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.

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.

timbo
  • 13,244
  • 8
  • 51
  • 71
  • All of the above is correct... I would recommend waiting (hopefully not very long) for XCode 7.3 to drop which has better integration with the Swift tool chain. – rougeExciter Mar 17 '16 at 17:08
2

June 4th, 2019 update. Swift 5 and SPM 5 has added this support and Xcode 11 integrates with SPM.

possen
  • 8,596
  • 2
  • 39
  • 48