33

I am using the new open source Swift Package Manager and am able to download the files. I want the manager to create a "development environment" (Through Xcode) based on the packages it retrieved.

Has anybody dealt with this?

Pascal
  • 16,846
  • 4
  • 60
  • 69
Avba
  • 14,822
  • 20
  • 92
  • 192
  • Reading the [documentation overview](https://swift.org/package-manager/#conceptual-overview) shows that what you are asking for is not a feature of the Package Manager. There's nothing about it either in the [Community Proposal](https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageManagerCommunityProposal.md). – Eric Aya Dec 06 '15 at 12:30
  • What you mean "development environment" ? – Kostiantyn Koval Dec 09 '15 at 12:35
  • 1
    @EricD: As of recently it now is a feature of the SPM! \o/ – Regexident Apr 12 '16 at 17:04

3 Answers3

46

Update: as mentioned in other answers, you can now generate Xcode project files with this command:

swift package generate-xcodeproj

Original answer:

The Swift Package Manger (SPM) is cross platform, It works on Mac and Linux. The Xcode is Mac OS only, so I don't think SPM will be hard integrate to work with Xcode.

SPM can do 2 things:

  • Build swift source code into modules (Executable and Library)
  • Fetch dependencies (from git or local path)

The SPM work only with Source code, folders and files. It doesn't know anything about Xcode.
Also it is mentioned that in the future Apple plans to add support for other languages not only Swift and Objc.

My answer: SPM will not ingrate with Xcode. But because it's open-source anyone can just make its own fork and add custom feature that would generate Xcode specific files.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Kostiantyn Koval
  • 8,407
  • 1
  • 45
  • 58
40

Update (2021/05/23):

With Xcode having gained official support for Swift Packages the recommended way to create packages these days is from within Xcode via "Xcode > File > New > Swift Package".


Update (2020/11/20):

With PR 3062 merged generate-xcodeproj will soon be marked as deprecated.


Original answer:

As of PR #174 on the swift-package-manager project, there exists an option for generating an Xcode project file in root directory of the package:

$ swift package generate-xcodeproj

Note: Earlier builds used:

$ swift build --generate-xcodeproj

It will officially be part of Swift's 3.0 release.
But it is already available with Xcode Swift DEVELOPMENT Snapshot 2016-03-24 or later!

Regexident
  • 29,441
  • 10
  • 93
  • 100
  • 2
    @RyanCollins: thanks, updated. There's really no need to downvote correct, yet newly outdated answers. Just write a comment (as you did) asking for an update edit. – Regexident Jun 10 '16 at 13:53
  • 1
    This answer is currently being discussed on [Meta](https://meta.stackoverflow.com/q/386908/8239061). – SecretAgentMan Jul 08 '19 at 15:23
  • @Regexident do you have any idea what's going to replace `swift package generate-xcodeproj`? Or should we just start projects directly from Xcode and integrate the Swift PM from there? – Avihu Turzion May 22 '21 at 12:37
  • With "Xcode > File > New > Swift Package" being available from Xcode I don't see Apple providing a replacement for `swift package generate-xcodeproj`. They simply needed the latter as a temporary workaround until the feature made it into Xcode. – Regexident May 23 '21 at 20:56
3

All you need to do now, if you had Xcode 11 installed is just run this command and xcode-tools will automatically open the appropriate Package.swift and resolve as an project for you to open in Xcode:

$ xed .

Pre 2020:

I wrote a small command line tool for that

it's called spawn: https://github.com/vinhnx/spawn

Basically, it's just a small combination of repetitive commands when you want to try out a SPM package:

$ swift package update # update or resolve package dependencies
$ swift package generate-xcodeproj # generate a .xcodeproj to edit on Xcode
$ xed . # open generated .xcodeproj automatically
Vinh Nguyen
  • 816
  • 1
  • 13
  • 27