Generate XCode Project via Swift Package Manager

Swift package manager provides a convention-based system for building libraries and executables, and sharing code across different projects. Before you can use it you should make it available on MacOS by installing Swift Open Source Toolchain.

Install  Package Manager

  1. Download the latest package release – select Toolchain Link under XCode 8.1*.
  2. Run the package installer, which will install an Xcode toolchain into/Library/Developer/Toolchains/.An Xcode toolchain (.xctoolchain) includes a copy of the compiler, lldb, and other related tools needed to provide a cohesive development experience for working in a specific version of Swift.
  3. Open Xcode’s Preferences, navigate to Components > Toolchains, and select the installed Swift toolchain.
  4. Xcode uses the selected toolchain for building Swift code, debugging, and even code completion and syntax coloring. You’ll see a new toolchain indicator in Xcode’s toolbar when Xcode is using a Swift toolchain. Select the Xcode toolchain to go back to Xcode’s built-in tools.
  5. Selecting a Swift toolchain affects the Xcode IDE only. To use the Swift toolchain with command-line tools add the Swift toolchain to your path as follows:
$ export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:"${PATH}"

After these steps you are able to run swift command – you’ll launch the REPL, an interactive shell that will read, evaluate, and print the results of any Swift code you enter.

Using the Package Manager

Follow the Getting Started and read the “Using the Package Manager section”. After reading you should have a base understanding about how to use the package manager. If you are familiar with Maven or npm you will see that package manager follows the same approach.

To learn more about the Swift Package Manager, including how to build modules, import dependencies, and map system libraries, see the Swift Package Manager section.

The package manager makes developer life much easier and it is even able to generate the XCode project files for you!


 swift package generate-xcodeproj

Awesome! With a simple command  you have created your XCode project setup and are able to navigate in all dependant package sources.

tomkausch

Leave a Reply

Your email address will not be published. Required fields are marked *