How to Install Package in Xcode via Swift Package Manager How to Install Package in Xcode via Swift Package Manager swift swift

How to Install Package in Xcode via Swift Package Manager


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".


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.


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