How to Install Package in Xcode via Swift Package Manager

独自空忆成欢 提交于 2019-12-02 21:52:29

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!