Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Swift Package Manager how can I generate an Xcode project file for development

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?

like image 891
Avner Barr Avatar asked Dec 06 '15 09:12

Avner Barr


People also ask

How do I create a Swift project in Xcode?

Launch Xcode, then click “Create a new Xcode project” in the Welcome to Xcode window or choose File > New > Project. In the sheet that appears, select the target operating system or platform and a template under Application. In the following sheets, fill out the forms and choose options to configure your project.


2 Answers

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.

like image 66
Kostiantyn Koval Avatar answered Sep 29 '22 15:09

Kostiantyn Koval


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!

like image 28
Regexident Avatar answered Sep 29 '22 14:09

Regexident